<?php

use App\Modules\HR\Employees\Controllers\EmployeeAssetAssignmentController;
use App\Modules\HR\Employees\Controllers\EmployeeDocumentDownloadController;
use App\Modules\HR\Employees\Controllers\EmployeeEmergencyContactController;
use App\Modules\HR\Employees\Controllers\EmployeeEmploymentHistoryController;
use App\Modules\HR\Employees\Controllers\EmployeePageController;
use App\Modules\HR\Employees\Controllers\EmployeeSkillController;
use App\Modules\HR\Employees\Controllers\EmployeeUserAccountController;
use Illuminate\Support\Facades\Route;

Route::prefix('hr/employees')->name('hr.employees.')->middleware('module:hr')->group(function () {
    Route::get('/', [EmployeePageController::class, 'index'])
        ->middleware('can:employees.view')
        ->name('index');

    Route::get('/create', [EmployeePageController::class, 'create'])
        ->middleware('can:employees.create')
        ->name('create');

    Route::post('/', [EmployeePageController::class, 'store'])
        ->middleware('can:employees.create')
        ->name('store');

    Route::get('/{employee}/documents/{document}/download', EmployeeDocumentDownloadController::class)
        ->middleware('can:employees.documents.view,employee')
        ->name('documents.download');

    Route::get('/{employee}', [EmployeePageController::class, 'show'])
        ->middleware('can:employees.view,employee')
        ->name('show');

    Route::get('/{employee}/edit', [EmployeePageController::class, 'edit'])
        ->middleware('can:employees.update,employee')
        ->name('edit');

    Route::put('/{employee}', [EmployeePageController::class, 'update'])
        ->middleware('can:employees.update,employee')
        ->name('update');

    Route::post('/{employee}/user-account', [EmployeeUserAccountController::class, 'store'])
        ->middleware('can:employees.update,employee')
        ->name('user-account.store');

    Route::post('/{employee}/user-account/link', [EmployeeUserAccountController::class, 'link'])
        ->middleware('can:employees.update,employee')
        ->name('user-account.link');

    Route::post('/{employee}/user-account/unlink', [EmployeeUserAccountController::class, 'unlink'])
        ->middleware('can:employees.update,employee')
        ->name('user-account.unlink');

    Route::post('/{employee}/deactivate', [EmployeePageController::class, 'deactivate'])
        ->middleware('can:employees.deactivate,employee')
        ->name('deactivate');

    Route::post('/{employee}/employment-histories', [EmployeeEmploymentHistoryController::class, 'store'])
        ->middleware('can:employees.update,employee')->name('employment-histories.store');
    Route::put('/{employee}/employment-histories/{employment_history}', [EmployeeEmploymentHistoryController::class, 'update'])
        ->middleware('can:employees.update,employee')->name('employment-histories.update');
    Route::delete('/{employee}/employment-histories/{employment_history}', [EmployeeEmploymentHistoryController::class, 'destroy'])
        ->middleware('can:employees.update,employee')->name('employment-histories.destroy');

    Route::post('/{employee}/emergency-contacts', [EmployeeEmergencyContactController::class, 'store'])
        ->middleware('can:employees.update,employee')
        ->name('emergency-contacts.store');
    Route::put('/{employee}/emergency-contacts/{emergency_contact}', [EmployeeEmergencyContactController::class, 'update'])
        ->middleware('can:employees.update,employee')
        ->name('emergency-contacts.update');
    Route::delete('/{employee}/emergency-contacts/{emergency_contact}', [EmployeeEmergencyContactController::class, 'destroy'])
        ->middleware('can:employees.update,employee')
        ->name('emergency-contacts.destroy');

    Route::post('/{employee}/skills', [EmployeeSkillController::class, 'store'])
        ->middleware('can:employees.update,employee')
        ->name('skills.store');
    Route::put('/{employee}/skills/{skill}', [EmployeeSkillController::class, 'update'])
        ->middleware('can:employees.update,employee')
        ->name('skills.update');
    Route::delete('/{employee}/skills/{skill}', [EmployeeSkillController::class, 'destroy'])
        ->middleware('can:employees.update,employee')
        ->name('skills.destroy');

    Route::post('/{employee}/assets', [EmployeeAssetAssignmentController::class, 'store'])
        ->middleware('can:employees.update,employee')
        ->name('assets.store');
    Route::put('/{employee}/assets/{asset_assignment}', [EmployeeAssetAssignmentController::class, 'update'])
        ->middleware('can:employees.update,employee')
        ->name('assets.update');
    Route::delete('/{employee}/assets/{asset_assignment}', [EmployeeAssetAssignmentController::class, 'destroy'])
        ->middleware('can:employees.update,employee')
        ->name('assets.destroy');
});
