<?php

namespace Modules\Inventory\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Modules\Core\Helpers\ApiResponse;
use Modules\Inventory\Services\UnitService;
use Modules\Inventory\DTO\InventorySettingFilter;
use Modules\Inventory\DTO\ProductListFilter;
use Modules\Inventory\Services\CategoryService;
use Modules\Inventory\Services\InventoryDepartmentService;
use Modules\Inventory\Services\ProductService;
use Modules\Inventory\Services\SupplierService;
use Modules\Inventory\Transformers\CategoryLookupResource;
use Modules\Inventory\Transformers\InventoryDepartmentResource;
use Modules\Inventory\Transformers\ProductResource;
use Modules\Inventory\Transformers\SupplierLookupResource;
use Modules\Inventory\Transformers\UnitLookupResource;

class InventoryLookupController extends Controller
{
    protected $unitService;
    protected $inventoryDepartmentService;
    protected $categoryService;
    protected $productService;
    protected $supplierService;

    public function __construct(
        UnitService $unitService,
        InventoryDepartmentService $inventoryDepartmentService,
        CategoryService $categoryService,
        ProductService $productService,
        SupplierService $supplierService
    ) {
        $this->unitService = $unitService;
        $this->inventoryDepartmentService = $inventoryDepartmentService;
        $this->categoryService = $categoryService;
        $this->productService = $productService;
        $this->supplierService = $supplierService;
    }

    public function unitList(Request $request)
    {
        $filters = InventorySettingFilter::fromRequest($request);
        $response = $this->unitService->LookUpList($filters);
        
        return (UnitLookupResource::collection($response))->additional([
            'status' => true,
            'message' => 'Units retrieved successfully.'
        ]);
    }

    public function inventoryDepartmentList(Request $request)
    {
        $filters = InventorySettingFilter::fromRequest($request);
        $response = $this->inventoryDepartmentService->lookUpList($filters);

        return (InventoryDepartmentResource::collection($response))->additional([
            'status' => true,
            'message' => 'Inventory departments retrieved successfully.'
        ]);
    }

    public function categoryList(Request $request)
    {
        $filters = InventorySettingFilter::fromRequest($request);
        $response = $this->categoryService->lookUpList($filters);

        return (CategoryLookupResource::collection($response))->additional([
            'status' => true,
            'message' => 'Categories retrieved successfully.'
        ]);
    }

    public function productList(Request $request)
    {
        $filter = ProductListFilter::fromRequest($request);
        $data = $this->productService->productLookupList($filter);

        return (ProductResource::collection($data))->additional([
            'status' => true,
            'message' => 'Products retrieved successfully.'
        ]);
    }
    public function supplierList(Request $request)
    {
        $filter = InventorySettingFilter::fromRequest($request);
        $data = $this->supplierService->lookUpList($filter);

        return (SupplierLookupResource::collection($data))->additional([
            'status' => true,
            'message' => 'Suppliers retrieved successfully.'
        ]);
    }
}
