<?php

use App\Modules\HR\EmployeeSelfService\Controllers\MeAttendanceCorrectionController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeAttendanceController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeDashboardController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeLeaveController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeLoanController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeNotificationController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeOvertimeController;
use App\Modules\HR\EmployeeSelfService\Controllers\MePayslipsPageController;
use App\Modules\HR\EmployeeSelfService\Controllers\MePermissionRequestController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeProfileController;
use App\Modules\HR\EmployeeSelfService\Controllers\MePortalResourcesController;
use App\Modules\HR\Performance\Controllers\PerformanceController;
use App\Modules\HR\EmployeeSelfService\Controllers\MeTeamAttendanceController;
use Illuminate\Support\Facades\Route;

Route::middleware(['module:hr'])->group(function () {
    Route::get('/dashboard', [MeDashboardController::class, 'index'])->name('dashboard');
    Route::get('/profile', [MeProfileController::class, 'show'])->name('profile');
    Route::get('/documents', [MePortalResourcesController::class, 'documents'])
        ->middleware('can:self_service.portal')->name('documents.index');
    Route::get('/documents/{document}/download', [MePortalResourcesController::class, 'downloadDocument'])
        ->whereNumber('document')->middleware('can:self_service.portal')->name('documents.download');
    Route::get('/training', [MePortalResourcesController::class, 'training'])
        ->middleware('can:self_service.portal')->name('training.index');
    Route::get('/assets', [MePortalResourcesController::class, 'assets'])
        ->middleware('can:self_service.portal')->name('assets.index');
    Route::get('/attendance', [MeAttendanceController::class, 'index'])->name('attendance.index');
    Route::post('/attendance/check-in', [MeAttendanceController::class, 'checkIn'])
        ->name('attendance.check-in');
    Route::post('/attendance/check-out', [MeAttendanceController::class, 'checkOut'])
        ->name('attendance.check-out');
    Route::get('/team/attendance', [MeTeamAttendanceController::class, 'index'])->name('team.attendance.index');
    Route::get('/attendance/corrections', [MeAttendanceCorrectionController::class, 'index'])
        ->name('attendance.corrections.index');
    Route::get('/attendance/corrections/create', [MeAttendanceCorrectionController::class, 'create'])
        ->name('attendance.corrections.create');
    Route::post('/attendance/corrections', [MeAttendanceCorrectionController::class, 'store'])
        ->name('attendance.corrections.store');
    Route::get('/leaves', [MeLeaveController::class, 'index'])->name('leaves.index');
    Route::get('/leaves/create', [MeLeaveController::class, 'create'])->name('leaves.create');
    Route::post('/leaves', [MeLeaveController::class, 'store'])->name('leaves.store');
    Route::post('/leaves/{leaveRequest}/cancel', [MeLeaveController::class, 'cancel'])
        ->whereNumber('leaveRequest')
        ->name('leaves.cancel');
    Route::get('/permission-requests', [MePermissionRequestController::class, 'index'])
        ->name('permission-requests.index');
    Route::get('/permission-requests/create', [MePermissionRequestController::class, 'create'])
        ->name('permission-requests.create');
    Route::post('/permission-requests', [MePermissionRequestController::class, 'store'])
        ->name('permission-requests.store');
    Route::get('/overtime', [MeOvertimeController::class, 'index'])->name('overtime.index');
    Route::get('/overtime/create', [MeOvertimeController::class, 'create'])->name('overtime.create');
    Route::post('/overtime', [MeOvertimeController::class, 'store'])->name('overtime.store');
    Route::get('/payslips', [MePayslipsPageController::class, 'index'])->name('payslips.index');
    Route::get('/loans', [MeLoanController::class, 'index'])->name('loans.index');
    Route::get('/loans/create', [MeLoanController::class, 'create'])->name('loans.create');
    Route::post('/loans', [MeLoanController::class, 'store'])->name('loans.store');
    Route::get('/performance', [PerformanceController::class, 'reviews'])->name('performance.index');
    Route::put('/performance/{review}/self', [PerformanceController::class, 'selfUpdate'])
        ->name('performance.self-update');
    Route::get('/payslips/{snapshot}', [MePayslipsPageController::class, 'show'])
        ->whereNumber('snapshot')
        ->name('payslips.show');
    Route::get('/notifications', [MeNotificationController::class, 'index'])->name('notifications.index');
    Route::post('/notifications/{id}/read', [MeNotificationController::class, 'markRead'])
        ->whereUuid('id')
        ->name('notifications.read');
    Route::post('/notifications/read-all', [MeNotificationController::class, 'markAllRead'])
        ->name('notifications.read-all');
});
