<?php

namespace Modules\Employee\Http\Controllers;

use App\Http\Controllers\Controller;
use Modules\Core\Helpers\ApiResponse;
use Modules\Employee\DTO\EmployeeListDTO;
use Modules\Employee\DTO\EmployeeSettingFilter;
use Modules\Employee\Models\EmploymentStatus;
use Modules\Employee\Services\BloodService;
use Modules\Employee\Services\BranchService;
use Modules\Employee\Services\DepartmentService;
use Modules\Employee\Services\DesignationService;
use Modules\Employee\Services\EducationLevelService;
use Modules\Employee\Services\EmployeeLookupService;
use Modules\Employee\Services\EmploymentStatusService;
use Modules\Employee\Services\ProjectService;
use Modules\Employee\Services\SalaryGradeService;
use Modules\Employee\Services\ShiftService;
use Modules\Employee\Services\StaffTypeService;
use Modules\Employee\Services\TerminationService;
use Modules\Employee\Transformers\BloodResource;
use Modules\Employee\Transformers\BranchResource;
use Modules\Employee\Transformers\CountryResource;
use Modules\Employee\Transformers\DepartmentResource;
use Modules\Employee\Transformers\DesignationLookupResource;
use Modules\Employee\Transformers\EducationLevelResource;
use Modules\Employee\Transformers\EmploymentStatusResource;
use Modules\Employee\Transformers\GenderResource;
use Modules\Employee\Transformers\MaritalStatusResource;
use Modules\Employee\Transformers\NationalityResource;
use Modules\Employee\Transformers\ProjectResource;
use Modules\Employee\Transformers\ReligionResource;
use Modules\Employee\Transformers\SalaryGradeResource;
use Modules\Employee\Transformers\ShiftLookUpResource;
use Modules\Employee\Transformers\StaffTypeResource;
use Modules\Employee\Transformers\TerminationResource;
use Symfony\Component\HttpFoundation\Request;

class EmployeeLookupController extends Controller
{

    protected $projectService;
    protected $branchService;
    protected $bloodService;
    protected $departmentService;
    protected $staffTypeService;
    protected $salaryGradeService;
    protected $designationService;
    protected $empStatusService;
    protected $eduLevelService;
    protected $terminationService;
    protected $shiftService;
    protected $employeeLookup;

    public function __construct(
        ProjectService $projectService,
        BranchService $branchService,
        DepartmentService $departmentService,
        StaffTypeService $staffTypeService,
        SalaryGradeService $salaryGradeService,
        BloodService $bloodService,
        DesignationService $designationService,
        EmploymentStatusService $empStatusService,
        EducationLevelService $eduLevelService,
        TerminationService $terminationService,
        ShiftService $shiftService,
        EmployeeLookupService $employeeLookup
    ) {
        $this->projectService = $projectService;
        $this->branchService = $branchService;
        $this->departmentService = $departmentService;
        $this->staffTypeService = $staffTypeService;
        $this->salaryGradeService = $salaryGradeService;
        $this->bloodService = $bloodService;
        $this->designationService = $designationService;
        $this->empStatusService = $empStatusService;
        $this->eduLevelService = $eduLevelService;
        $this->terminationService = $terminationService;
        $this->shiftService = $shiftService;
        $this->employeeLookup = $employeeLookup;
    }

    public function projectList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->projectService->list($filter);

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

    public function branchList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->branchService->list($filter);

        return (BranchResource::collection($data))->additional([
            'status' => true,
            'message' => 'Branches retrieved successfully.'
        ]);
    }
    public function  departmentList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->departmentService->list($filter);

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

    public function  staffTypeList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->staffTypeService->list($filter);

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


    public function  salaryGradeList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->salaryGradeService->list($filter);

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

    public function bloodList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->bloodService->list($filter);

        return (BloodResource::collection($data))->additional([
            'status' => true,
            'message' => 'Bloods retrieved successfully.'
        ]);
    }
    public function designationList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->designationService->list($filter);

        return (DesignationLookupResource::collection($data))->additional([
            'status' => true,
            'message' => 'Designation retrieved successfully.'
        ]);
    }
    public function empStatusList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->empStatusService->list($filter);

        return (EmploymentStatusResource::collection($data))->additional([
            'status' => true,
            'message' => 'Employment Statuses retrieved successfully.'
        ]);
    }
    public function eduLevelList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->eduLevelService->list($filter);

        return (EducationLevelResource::collection($data))->additional([
            'status' => true,
            'message' => 'Education levels retrieved successfully.'
        ]);
    }
    public function terminationList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->terminationService->list($filter);

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

    public function genderList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->employeeLookup->genderList($filter);

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

    public function shiftList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->shiftService->lookUpList($filter);

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


    public function countryList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->employeeLookup->countryList($filter);

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

    public function nationalityList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->employeeLookup->nationalityList($filter);

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

    public function religionList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->employeeLookup->religionList($filter);

        return ReligionResource::collection($data)->additional([
            'status' => true,
            'message' => 'Religions retrieved successfully.'
        ]);
    }
    public function maritalStatusList(Request $request)
    {
        $filter = EmployeeSettingFilter::fromRequest($request);
        $data = $this->employeeLookup->maritalStatusList($filter);

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

    public function employeeFind($id)
    {
        $response = $this->employeeLookup->employeeFind($id);

        return ApiResponse::successResponse(
            message: 'Employee retrieved successfully.',
            data: $response
        );
    }

    public function employeesList(Request $request)
    {
        $filters = EmployeeListDTO::fromRequest($request);
        $response = $this->employeeLookup->employeesList($filters);

        return ApiResponse::successResponse(
            message: 'Employee list retrieved successfully.',
            data: $response
        );
    }
}
