<?php

use App\Http\Controllers\PayrollController;
use Illuminate\Support\Facades\Route;

Route::middleware(['auth','module:payroll'])->group(function (): void {
    Route::get('/payroll', [PayrollController::class, 'index'])->middleware('permission:payroll.view')->name('payroll.index');
    Route::get('/payroll/compensations', [PayrollController::class, 'compensations'])->middleware('permission:payroll.compensation.manage')->name('payroll.compensations');
    Route::put('/payroll/compensations/{employee}', [PayrollController::class, 'updateCompensation'])->middleware('permission:payroll.compensation.manage')->name('payroll.compensations.update');
    Route::get('/payroll/create', [PayrollController::class, 'create'])->middleware('permission:payroll.periods.create')->name('payroll.create');
    Route::post('/payroll', [PayrollController::class, 'store'])->middleware('permission:payroll.periods.create')->name('payroll.store');
    Route::get('/payroll/{period}', [PayrollController::class, 'show'])->middleware(['permission:payroll.view','can:view,period'])->name('payroll.show');
    Route::put('/payroll/{period}/entries/{entry}', [PayrollController::class, 'updateEntry'])->middleware(['permission:payroll.periods.create','can:updateEntries,period'])->name('payroll.entries.update');
    Route::post('/payroll/{period}/decision', [PayrollController::class, 'decision'])->middleware(['permission:payroll.approve','can:decide,period'])->name('payroll.decision');
    Route::post('/payroll/{period}/pay', [PayrollController::class, 'pay'])->middleware(['permission:payroll.pay','can:pay,period'])->name('payroll.pay');
    Route::get('/payroll/{period}/entries/{entry}/payslip', [PayrollController::class, 'payslip'])->middleware(['permission:payroll.view','can:view,period'])->name('payroll.payslip');
    Route::get('/payroll/{period}/entries/{entry}/payslip.pdf', [PayrollController::class, 'payslipPdf'])->middleware(['permission:payroll.view','can:view,period'])->name('payroll.payslip.pdf');
});
