<?php

use App\Modules\HR\Shifts\Controllers\EmployeeShiftAssignmentPageController;
use App\Modules\HR\Shifts\Controllers\ShiftPageController;
use App\Modules\HR\Shifts\Controllers\ShiftCalendarController;
use Illuminate\Support\Facades\Route;

Route::prefix('hr/shifts')->name('hr.shifts.')->middleware('module:hr')->group(function () {
    Route::get('/calendar', [ShiftCalendarController::class, 'index'])
        ->middleware('can:shifts.view')->name('calendar');
    Route::post('/rotations', [ShiftCalendarController::class, 'storeRotation'])
        ->middleware('can:shifts.assign')->name('rotations.store');
    Route::post('/swaps', [ShiftCalendarController::class, 'storeSwap'])
        ->middleware('can:shifts.assign')->name('swaps.store');
    Route::post('/swaps/{swap}/review', [ShiftCalendarController::class, 'reviewSwap'])
        ->middleware('can:shifts.assign')->name('swaps.review');

    Route::get('/', [ShiftPageController::class, 'index'])
        ->middleware('can:shifts.view')
        ->name('index');

    Route::get('/create', [ShiftPageController::class, 'create'])
        ->middleware('can:shifts.create')
        ->name('create');

    Route::post('/', [ShiftPageController::class, 'store'])
        ->middleware('can:shifts.create')
        ->name('store');

    Route::get('/assignments', [EmployeeShiftAssignmentPageController::class, 'index'])
        ->middleware('can:shifts.view')
        ->name('assignments.index');

    Route::get('/assignments/create', [EmployeeShiftAssignmentPageController::class, 'create'])
        ->middleware('can:shifts.assign')
        ->name('assignments.create');

    Route::post('/assignments', [EmployeeShiftAssignmentPageController::class, 'store'])
        ->middleware('can:shifts.assign')
        ->name('assignments.store');

    Route::post('/assignments/{assignment}/end', [EmployeeShiftAssignmentPageController::class, 'end'])
        ->whereNumber('assignment')
        ->middleware('can:shifts.assign')
        ->name('assignments.end');

    Route::get('/{shift}/edit', [ShiftPageController::class, 'edit'])
        ->middleware('can:shifts.update,shift')
        ->name('edit');

    Route::put('/{shift}', [ShiftPageController::class, 'update'])
        ->middleware('can:shifts.update,shift')
        ->name('update');

    Route::post('/{shift}/deactivate', [ShiftPageController::class, 'deactivate'])
        ->middleware('can:shifts.deactivate,shift')
        ->name('deactivate');

    Route::post('/{shift}/reactivate', [ShiftPageController::class, 'reactivate'])
        ->middleware('can:shifts.update,shift')
        ->name('reactivate');
});
