<?php

use App\Http\Controllers\Employee\DashboardController;
use App\Http\Controllers\Employee\ProfileController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth', 'employee'])->prefix('employee')->name('employee.')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');

    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::put('/profile/info', [ProfileController::class, 'updateInfo'])->name('profile.update_info');
    Route::put('/profile/image', [ProfileController::class, 'updateImage'])->name('profile.update_image');
    Route::put('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.update_password');

    // Notifications
    Route::get('/notifications', [App\Http\Controllers\Employee\NotificationController::class, 'index'])->name('notifications.index');
    Route::get('/notifications/recent', [App\Http\Controllers\Employee\NotificationController::class, 'recent'])->name('notifications.recent');
    Route::post('/notifications/{id}/read', [App\Http\Controllers\Employee\NotificationController::class, 'markAsRead'])->name('notifications.read');
    Route::post('/notifications/read-all', [App\Http\Controllers\Employee\NotificationController::class, 'markAllAsRead'])->name('notifications.read_all');
    Route::delete('/notifications/{id}', [App\Http\Controllers\Employee\NotificationController::class, 'destroy'])->name('notifications.destroy');

    // Attendance
    Route::get('/attendance/export', [\App\Http\Controllers\Admin\AttendanceExportController::class, 'export'])->name('attendance.export');
    Route::get('/attendance', [\App\Http\Controllers\AttendanceController::class, 'index'])->name('attendance.index');
    Route::get('/my-team', [\App\Http\Controllers\Employee\MyTeamController::class, 'index'])->name('my-team.index');
    Route::post('/attendance/clock-in', [\App\Http\Controllers\AttendanceController::class, 'clockIn'])->name('attendance.clock_in');
    Route::post('/attendance/clock-out', [\App\Http\Controllers\AttendanceController::class, 'clockOut'])->name('attendance.clock_out');
    Route::post('/attendance/start-break', [\App\Http\Controllers\AttendanceController::class, 'startBreak'])->name('attendance.start_break');
    Route::post('/attendance/end-break', [\App\Http\Controllers\AttendanceController::class, 'endBreak'])->name('attendance.end_break');
    Route::post('/attendance/manual-entry', [\App\Http\Controllers\AttendanceController::class, 'manualEntry'])->name('attendance.manual_entry');

    // Leave
    Route::get('/leave', [\App\Http\Controllers\Employee\LeaveRequestController::class, 'index'])->name('leave.index');
    Route::post('/leave', [\App\Http\Controllers\Employee\LeaveRequestController::class, 'store'])->name('leave.store');

    // Manager - Attendance Approvals
    Route::get('/manager/attendance/approvals', [App\Http\Controllers\Manager\AttendanceApprovalController::class, 'index'])->name('manager.attendance.approvals');
    Route::post('/manager/attendance/{attendance}/approve', [App\Http\Controllers\Manager\AttendanceApprovalController::class, 'approve'])->name('manager.attendance.approve');
    Route::post('/manager/attendance/{attendance}/reject', [App\Http\Controllers\Manager\AttendanceApprovalController::class, 'reject'])->name('manager.attendance.reject');

    // Manager - Leave Approvals
    Route::get('/manager/leave/approvals', [App\Http\Controllers\Manager\LeaveApprovalController::class, 'index'])->name('manager.leave.approvals');
    Route::post('/manager/leave/{leaveRequest}/approve', [App\Http\Controllers\Manager\LeaveApprovalController::class, 'approve'])->name('manager.leave.approve');
    Route::post('/manager/leave/{leaveRequest}/reject', [App\Http\Controllers\Manager\LeaveApprovalController::class, 'reject'])->name('manager.leave.reject');

    // Assets
    Route::get('/assets', [\App\Http\Controllers\Employee\AssetController::class, 'index'])->name('assets.index');

    // Announcements
    Route::get('/announcements', [\App\Http\Controllers\Employee\AnnouncementController::class, 'index'])->name('announcements.index');
    Route::get('/announcements/{announcement}', [\App\Http\Controllers\Employee\AnnouncementController::class, 'show'])->name('announcements.show');

    // Loans
    Route::post('/loans/{loan}/send-for-approval', [\App\Http\Controllers\Employee\EmployeeLoanController::class, 'sendForApproval'])->name('loans.send_for_approval');
    Route::resource('loans', \App\Http\Controllers\Employee\EmployeeLoanController::class)->only(['index', 'store', 'update', 'destroy']);
    // Salary Certificates
    Route::get('/salary-certificates', [\App\Http\Controllers\Employee\SalaryCertificateController::class, 'index'])->name('salary-certificates.index');
    Route::post('/salary-certificates', [\App\Http\Controllers\Employee\SalaryCertificateController::class, 'store'])->name('salary-certificates.store');
    Route::get('/salary-certificates/{salaryCertificateRequest}/download', [\App\Http\Controllers\Employee\SalaryCertificateController::class, 'download'])->name('salary-certificates.download');
});
