<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\{AuthController,DashboardController,EmployeePortalController,InternPortalController,AttendanceController,EmployeeController,InternController,ProjectController,TaskController,SecuritySettingsController,PayrollController,ExpenseController,LeaveController,AdminResourceController,WorkforceCrudController,AttendanceAdminController,StipendController,InternDevelopmentController,PerformanceController,DocumentController,AssetLifecycleController,OffboardingController,ReportController,PayslipController,MfaController,PasswordController,VerifyEmailController,ApprovalController,ProductionHealthController};

Route::get('/health/production',ProductionHealthController::class)->name('health.production');
Route::middleware('guest')->group(function(){
 Route::get('/login',[AuthController::class,'create'])->name('login'); Route::post('/login',[AuthController::class,'store'])->name('login.store');
 Route::get('/forgot-password',[PasswordController::class,'forgot'])->name('password.request'); Route::post('/forgot-password',[PasswordController::class,'email'])->name('password.email');
 Route::get('/reset-password/{token}',[PasswordController::class,'resetForm'])->name('password.reset'); Route::post('/reset-password',[PasswordController::class,'reset'])->name('password.update');
});
Route::middleware('auth')->group(function(){
 Route::post('/logout',[AuthController::class,'destroy'])->name('logout');
 Route::get('/email/verify',[VerifyEmailController::class,'notice'])->name('verification.notice'); Route::get('/email/verify/{id}/{hash}',[VerifyEmailController::class,'verify'])->middleware('signed')->name('verification.verify'); Route::post('/email/verification-notification',[VerifyEmailController::class,'send'])->middleware('throttle:6,1')->name('verification.send');
 Route::get('/mfa',[MfaController::class,'challenge'])->name('mfa.challenge'); Route::post('/mfa',[MfaController::class,'verify'])->middleware('throttle:6,1')->name('mfa.verify');
 Route::middleware(['mfa','verified'])->group(function(){
  Route::get('/',DashboardController::class)->name('dashboard');
  Route::get('/employee',[EmployeePortalController::class,'dashboard'])->middleware('role:employee')->name('employee.dashboard');
  Route::get('/intern',[InternPortalController::class,'dashboard'])->middleware('role:intern')->name('intern.dashboard');
  Route::get('/attendance',[AttendanceController::class,'index'])->name('attendance.index'); Route::post('/attendance/punch',[AttendanceController::class,'punch'])->middleware('throttle:10,1')->name('attendance.punch');
  Route::post('/attendance/remote',[AttendanceAdminController::class,'requestRemote'])->name('attendance.remote');
  Route::get('/leave',[LeaveController::class,'index'])->name('leave.index'); Route::post('/leave',[LeaveController::class,'store'])->name('leave.store');
  Route::post('/expenses',[ExpenseController::class,'store'])->name('expenses.store');
  Route::get('/payslips/{item}',[PayslipController::class,'show'])->name('payslips.show');

  Route::middleware('permission:people.manage')->group(function(){
   Route::get('/employees',[EmployeeController::class,'index'])->name('employees.index'); Route::post('/employees',[WorkforceCrudController::class,'storeEmployee'])->name('employees.store'); Route::patch('/employees/{employee}',[WorkforceCrudController::class,'updateEmployee'])->name('employees.update'); Route::delete('/employees/{employee}',[WorkforceCrudController::class,'destroyEmployee'])->name('employees.destroy');
   Route::get('/interns',[InternController::class,'index'])->name('interns.index'); Route::post('/interns',[WorkforceCrudController::class,'storeIntern'])->name('interns.store'); Route::patch('/interns/{intern}',[WorkforceCrudController::class,'updateIntern'])->name('interns.update'); Route::delete('/interns/{intern}',[WorkforceCrudController::class,'destroyIntern'])->name('interns.destroy');
   Route::get('/interns/{intern}/development',[InternDevelopmentController::class,'show'])->name('interns.development'); Route::post('/interns/{intern}/learning',[InternDevelopmentController::class,'learning'])->name('interns.learning'); Route::post('/interns/{intern}/evaluate',[InternDevelopmentController::class,'evaluate'])->name('interns.evaluate'); Route::post('/interns/{intern}/certificate',[InternDevelopmentController::class,'certificate'])->name('interns.certificate');
   Route::get('/documents',[DocumentController::class,'index'])->name('documents.index'); Route::post('/documents',[DocumentController::class,'store'])->name('documents.store');
   Route::get('/offboarding',[OffboardingController::class,'index'])->name('offboarding.index'); Route::post('/offboarding',[OffboardingController::class,'store'])->name('offboarding.store'); Route::post('/offboarding/{offboarding}/complete',[OffboardingController::class,'complete'])->name('offboarding.complete');
  });
  Route::get('/documents/{document}/download',[DocumentController::class,'download'])->name('documents.download');
  Route::middleware('permission:attendance.review')->group(function(){Route::get('/attendance-admin',[AttendanceAdminController::class,'index'])->name('attendance.admin');Route::post('/attendance/lock',[AttendanceAdminController::class,'lock'])->name('attendance.lock');});
Route::middleware('permission:projects.manage')->group(function(){Route::get('/projects',[ProjectController::class,'index'])->name('projects.index');Route::post('/projects',[ProjectController::class,'store'])->name('projects.store');Route::get('/projects/{project}',[ProjectController::class,'show'])->name('projects.show');Route::patch('/projects/{project}',[ProjectController::class,'update'])->name('projects.update');Route::delete('/projects/{project}',[ProjectController::class,'destroy'])->name('projects.destroy');Route::post('/projects/{project}/members',[ProjectController::class,'member'])->name('projects.members.store');Route::get('/tasks',[TaskController::class,'index'])->name('tasks.index');Route::post('/tasks',[TaskController::class,'store'])->name('tasks.store');Route::patch('/tasks/{task}/status',[TaskController::class,'updateStatus'])->name('tasks.status');});
  Route::middleware('permission:payroll.manage')->group(function(){Route::get('/payroll',[PayrollController::class,'index'])->name('payroll.index');Route::post('/payroll/calculate',[PayrollController::class,'calculate'])->name('payroll.calculate');Route::post('/payroll/{batch}/approve',[PayrollController::class,'approve'])->name('payroll.approve');Route::post('/payroll/{batch}/paid',[PayrollController::class,'paid'])->name('payroll.paid');Route::get('/stipends',[StipendController::class,'index'])->name('stipends.index');Route::post('/stipends/calculate',[StipendController::class,'calculate'])->name('stipends.calculate');Route::post('/stipends/{batch}/approve',[StipendController::class,'approve'])->name('stipends.approve');Route::post('/stipends/{batch}/paid',[StipendController::class,'paid'])->name('stipends.paid');});
  Route::middleware('permission:expenses.approve')->group(function(){Route::get('/expenses',[ExpenseController::class,'index'])->name('expenses.index');});
  Route::middleware('permission:performance.manage')->group(function(){Route::get('/performance',[PerformanceController::class,'index'])->name('performance.index');Route::post('/performance/reviews',[PerformanceController::class,'review'])->name('performance.review');Route::post('/performance/employees/{employee}/kpi',[PerformanceController::class,'kpi'])->name('performance.kpi');});
  Route::middleware('permission:assets.manage')->group(function(){Route::post('/assets/{asset}/assign',[AssetLifecycleController::class,'assign'])->name('assets.assign');Route::post('/assets/{asset}/return',[AssetLifecycleController::class,'returnAsset'])->name('assets.return');});
  Route::middleware('permission:reports.view')->group(function(){Route::get('/reports',[ReportController::class,'index'])->name('reports.index');Route::get('/reports/csv/{type}',[ReportController::class,'csv'])->name('reports.csv');Route::get('/reports/pdf/{type}',[ReportController::class,'pdf'])->name('reports.pdf');});
  Route::middleware('permission:settings.manage')->group(function(){Route::get('/security-settings',[SecuritySettingsController::class,'index'])->name('security.index');Route::post('/security-settings/roles',[SecuritySettingsController::class,'role'])->name('security.role.store');Route::patch('/security-settings/roles/{role}',[SecuritySettingsController::class,'sync'])->name('security.role.sync');Route::post('/security-settings/ip-rules',[SecuritySettingsController::class,'ip'])->name('security.ip.store');Route::delete('/security-settings/ip-rules/{rule}',[SecuritySettingsController::class,'deleteIp'])->name('security.ip.delete');Route::get('/admin/{resource}',[AdminResourceController::class,'index'])->whereIn('resource',['departments','offices','shifts','clients','holidays','expense-categories','leave-types','assets','performance-cycles'])->name('admin.resources.index');Route::post('/admin/{resource}',[AdminResourceController::class,'store'])->name('admin.resources.store');Route::patch('/admin/{resource}/{id}',[AdminResourceController::class,'update'])->name('admin.resources.update');Route::delete('/admin/{resource}/{id}',[AdminResourceController::class,'destroy'])->name('admin.resources.destroy');});
  Route::post('/approvals/{type}/{id}',[ApprovalController::class,'act'])->name('approvals.act');
 });
});
