<?php

use Illuminate\Support\Facades\Route;
use Modules\Employee\Http\Controllers\BloodController;
use Modules\Employee\Http\Controllers\BranchController;
use Modules\Employee\Http\Controllers\DepartmentController;
use Modules\Employee\Http\Controllers\DesignationController;
use Modules\Employee\Http\Controllers\EducationLevelController;
use Modules\Employee\Http\Controllers\EmployeeController;
use Modules\Employee\Http\Controllers\EmployeeHolidayGroupController;
use Modules\Employee\Http\Controllers\EmployeeLookupController;
use Modules\Employee\Http\Controllers\EmployeeTerminationController;
use Modules\Employee\Http\Controllers\EmploymentStatusController;
use Modules\Employee\Http\Controllers\ProjectController;
use Modules\Employee\Http\Controllers\SalaryGradeController;
use Modules\Employee\Http\Controllers\ShiftController;
use Modules\Employee\Http\Controllers\StaffTypeController;
use Modules\Employee\Http\Controllers\TerminationController;

Route::middleware(['api.auth'])->prefix('employee-management')->group(function () {
    Route::apiResource('projects', ProjectController::class)->except('destroy');
    Route::patch('projects/{project}/status', [ProjectController::class, 'updateStatus'])
        ->name('projects.update-status');

    Route::apiResource('branches', BranchController::class)->except('destroy');
    Route::patch('branches/{branch}/status', [BranchController::class, 'updateStatus'])
        ->name('branches.update-status');

    Route::apiResource('departments', DepartmentController::class)->except('destroy');
    Route::patch('departments/{department}/status', [DepartmentController::class, 'updateStatus'])
        ->name('departments.update-status');

    Route::apiResource('staff-types', StaffTypeController::class)->except('destroy');
    Route::patch('staff-types/{staff_type}/status', [StaffTypeController::class, 'updateStatus'])
        ->name('staff-types.update-status');

    Route::apiResource('salary-grades', SalaryGradeController::class)->except('destroy');
    Route::patch('salary-grades/{salary_grade}/status', [SalaryGradeController::class, 'updateStatus'])
        ->name('salary-grades.update-status');

    Route::apiResource('bloods', BloodController::class)->except('destroy');
    Route::patch('bloods/{blood}/status', [BloodController::class, 'updateStatus'])
        ->name('bloods.update-status');

    Route::apiResource('designations', DesignationController::class)->except('destroy');
    Route::patch('designations/{designation}/status', [DesignationController::class, 'updateStatus'])
        ->name('designations.update-status');

    Route::apiResource('emp-statuses', EmploymentStatusController::class)->except('destroy');
    Route::patch('emp-statuses/{emp_status}/status', [EmploymentStatusController::class, 'updateStatus'])
        ->name('emp-statuses.update-status');

    Route::apiResource('employees', EmployeeController::class)->except('destroy');

    Route::prefix('employees/{employee}')->group(function () {
        Route::put('profile-picture', [EmployeeController::class, 'updateProfilePicture']);

        Route::get('contact', [EmployeeController::class, 'showContact']);
        Route::put('contact', [EmployeeController::class, 'updateContact']);
        Route::get('emergency-contact', [EmployeeController::class, 'showEmergencyContact']);
        Route::put('emergency-contact', [EmployeeController::class, 'updateEmergencyContact']);
        Route::delete('emergency-contact', [EmployeeController::class, 'destroyEmergencyContact']);
        Route::get('job-details', [EmployeeController::class, 'showJobDetails']);
        Route::put('job-details', [EmployeeController::class, 'updateJobDetails']);
        Route::get('salary', [EmployeeController::class, 'showSalary']);
        Route::put('salary', [EmployeeController::class, 'updateSalary']);

        Route::get('payroll-settings', [EmployeeController::class, 'showPayrollSettings']);
        Route::put('payroll-settings', [EmployeeController::class, 'updatePayrollSettings']);


        Route::get('qualifications', [EmployeeController::class, 'showQualifications']);
        Route::put('education', [EmployeeController::class, 'updateEducation']);
        Route::delete('education', [EmployeeController::class, 'destroyEducation']);
        Route::put('experience', [EmployeeController::class, 'updateExperience']);
        Route::delete('experience', [EmployeeController::class, 'destroyExperience']);


        Route::get('attachments', [EmployeeController::class, 'showAttachment']);
        Route::put('attachments', [EmployeeController::class, 'updateAttachment']);
        Route::delete('attachments', [EmployeeController::class, 'destroyAttachment']);

        Route::get('user', [EmployeeController::class, 'showUser']);
        Route::put('user', [EmployeeController::class, 'storeUser']);

        Route::post('terminate', [EmployeeTerminationController::class, 'store']);
        Route::post('activate', [EmployeeTerminationController::class, 'activate']);
        Route::get('terminate-show', [EmployeeTerminationController::class, 'show']);
        Route::post('update-termination', [EmployeeTerminationController::class, 'update']);
    });

    Route::post('employees/{employee}/grant-access', [EmployeeController::class, 'grantAccess']);
    Route::apiResource('edu-levels', EducationLevelController::class);

    Route::patch('edu-levels/{edu_level}/status', [EducationLevelController::class, 'updateStatus'])
        ->name('edu-levels.update-status');

    Route::apiResource('terminations', TerminationController::class);
    Route::patch('terminations/{termination}/status', [TerminationController::class, 'updateStatus'])
        ->name('terminations.update-status');


    Route::apiResource('shifts', ShiftController::class)->except('destroy');
    Route::patch('shifts/{shift}/status', [ShiftController::class, 'updateStatus'])
        ->name('shifts.update-status');

    Route::post('employee-holiday-groups/assign', [EmployeeHolidayGroupController::class, 'assign']);
    Route::get('employee-holiday-groups', [EmployeeHolidayGroupController::class, 'employeeHolidayGroups']);
    Route::get('employee-holiday-groups/{id}', [EmployeeHolidayGroupController::class, 'showEmployeeHolidayGroups']);
    Route::post('employee-holiday-groups/remove', [EmployeeHolidayGroupController::class, 'remove']);
    Route::post('employee-holiday-groups/transfer', [EmployeeHolidayGroupController::class, 'transfer']);
});


Route::middleware(['api.auth'])->prefix('employee/lookups')->group(function () {
    Route::get('projects', [EmployeeLookupController::class, 'projectList']);
    Route::get('branches', [EmployeeLookupController::class, 'branchList']);
    Route::get('departments', [EmployeeLookupController::class, 'departmentList']);
    Route::get('staff-types', [EmployeeLookupController::class, 'staffTypeList']);
    Route::get('shifts', [EmployeeLookupController::class, 'shiftList']);
    Route::get('salary-grades', [EmployeeLookupController::class, 'salaryGradeList']);
    Route::get('bloods', [EmployeeLookupController::class, 'bloodList']);
    Route::get('designations', [EmployeeLookupController::class, 'designationList']);
    Route::get('emp-statuses', [EmployeeLookupController::class, 'empStatusList']);
    Route::get('edu-levels', [EmployeeLookupController::class, 'eduLevelList']);
    Route::get('terminations', [EmployeeLookupController::class, 'terminationList']);
    Route::get('genders', [EmployeeLookupController::class, 'genderList']);

    Route::get('countries', [EmployeeLookupController::class, 'countryList']);
    Route::get('nationalities', [EmployeeLookupController::class, 'nationalityList']);
    Route::get('religions', [EmployeeLookupController::class, 'religionList']);
    Route::get('marital-statuses', [EmployeeLookupController::class, 'maritalStatusList']);

    Route::get('employees/{id}', [EmployeeLookupController::class, 'employeeFind']);
    Route::get('employees', [EmployeeLookupController::class, 'employeesList']);
});
