<?php

use App\Modules\Payroll\Controllers\PayrollPeriodsPageController;
use App\Modules\Payroll\Controllers\PayrollPayslipsPageController;
use Illuminate\Support\Facades\Route;

Route::middleware(['web', 'auth', 'verified', 'subscription.writable', 'module:hr'])->prefix('payroll')->name('payroll.')->group(function () {
    Route::get('/periods', [PayrollPeriodsPageController::class, 'index'])
        ->middleware('can:payroll.view')
        ->name('periods.index');
    Route::get('/periods/create', [PayrollPeriodsPageController::class, 'create'])
        ->middleware('can:payroll.process')
        ->name('periods.create');
    Route::post('/periods', [PayrollPeriodsPageController::class, 'store'])
        ->middleware('can:payroll.process')
        ->name('periods.store');
    Route::get('/periods/{period}', [PayrollPeriodsPageController::class, 'show'])
        ->whereNumber('period')
        ->middleware('can:payroll.view')
        ->name('periods.show');
    Route::post('/periods/{period}/process', [PayrollPeriodsPageController::class, 'process'])
        ->whereNumber('period')
        ->middleware('can:payroll.process')
        ->name('periods.process');
    Route::post('/periods/{period}/finalize', [PayrollPeriodsPageController::class, 'finalize'])
        ->whereNumber('period')
        ->middleware('can:payroll.finalize')
        ->name('periods.finalize');
    Route::post('/periods/{period}/adjustments', [PayrollPeriodsPageController::class, 'storeAdjustment'])
        ->whereNumber('period')
        ->middleware('can:payroll.adjustments.manage')
        ->name('periods.adjustments.store');

    Route::get('/payslips/{snapshot}', [PayrollPayslipsPageController::class, 'show'])
        ->whereNumber('snapshot')
        ->middleware('can:payroll.payslips.view')
        ->name('payslips.show');
});
