<?php

use Illuminate\Support\Facades\Route;
use Modules\MedWorkforce\Http\Controllers\ComplianceController;
use Modules\MedWorkforce\Http\Controllers\InstallController;
use Modules\MedWorkforce\Http\Controllers\RosterController;
use Modules\MedWorkforce\Http\Controllers\SwapController;
use Modules\MedWorkforce\Http\Controllers\TemplateController;

/*
|--------------------------------------------------------------------------
| MedWorkforce Back-Office (Blade, inside the ERP UI)
|--------------------------------------------------------------------------
| Session-authenticated routes rendered with the ERP master layout — the SAME
| middleware stack as the MedBilling / MedNotify modules. UI lives under
| `med-workforce`. Controllers guard with medwf.* permissions.
*/

// Install / Update routes (superadmin-gated inside the controller).
Route::middleware(['web', 'auth'])->prefix('med-workforce')->group(function () {
    Route::get('/install', [InstallController::class, 'index']);
    Route::post('/install', [InstallController::class, 'install']);
    Route::get('/uninstall', [InstallController::class, 'uninstall']);
    Route::get('/update', [InstallController::class, 'update']);
    Route::get('/repair', [InstallController::class, 'repair']);
});

// Back-office UI (P7-T1). Mirrors the MedBilling middleware stack.
Route::middleware(['web', 'auth', 'SetSessionData', 'language', 'timezone', 'AdminSidebarMenu', 'module:MedWorkforce'])
    ->prefix('med-workforce')
    ->name('medwf.')
    ->group(function () {
        // Duty-roster board (weekly grid → assign / edit / bulk / swap).
        Route::get('roster', [RosterController::class, 'index'])->name('roster.index');
        Route::get('roster/cell', [RosterController::class, 'cell'])->name('roster.cell');
        Route::post('roster', [RosterController::class, 'store'])->name('roster.store');
        Route::delete('roster/{id}', [RosterController::class, 'destroy'])->name('roster.destroy');
        Route::get('roster/bulk', [RosterController::class, 'bulkForm'])->name('roster.bulk');
        Route::post('roster/bulk', [RosterController::class, 'bulkStore'])->name('roster.bulk.store');

        // Shift-template CRUD.
        Route::get('templates', [TemplateController::class, 'index'])->name('templates.index');
        Route::get('templates/create', [TemplateController::class, 'create'])->name('templates.create');
        Route::post('templates', [TemplateController::class, 'store'])->name('templates.store');
        Route::get('templates/{id}/edit', [TemplateController::class, 'edit'])->name('templates.edit');
        Route::put('templates/{id}', [TemplateController::class, 'update'])->name('templates.update');
        Route::delete('templates/{id}', [TemplateController::class, 'destroy'])->name('templates.destroy');

        // Swap requests (list + raise + approve/reject).
        Route::get('swaps', [SwapController::class, 'index'])->name('swaps.index');
        Route::post('swaps', [SwapController::class, 'store'])->name('swaps.store');
        Route::post('swaps/{id}/approve', [SwapController::class, 'approve'])->name('swaps.approve');
        Route::post('swaps/{id}/reject', [SwapController::class, 'reject'])->name('swaps.reject');

        // Credential-compliance dashboard (+ review items).
        Route::get('compliance', [ComplianceController::class, 'index'])->name('compliance.index');
        Route::get('compliance/review', [ComplianceController::class, 'reviewForm'])->name('compliance.review');
        Route::post('compliance/review', [ComplianceController::class, 'reviewStore'])->name('compliance.review.store');
        Route::delete('compliance/review/{id}', [ComplianceController::class, 'reviewDestroy'])->name('compliance.review.destroy');
    });
