<?php 

use Illuminate\Support\Facades\Route;
use Portal\Mileage\Http\Controllers\ApplyformController;
use Portal\Mileage\Http\Controllers\ApplicationsController;
use Portal\Mileage\Http\Controllers\ProjectManagerController;
use Portal\Mileage\Http\Controllers\ProjectDirectorController;
use Portal\Mileage\Http\Controllers\HODController;
use Portal\Mileage\Http\Controllers\BODController;
use Portal\Mileage\Http\Controllers\HRController;
use Portal\Mileage\Http\Controllers\FinanceController;

Route::group(
    [
        'prefix'     => '',
        'as'         => 'mileage::',
        'middleware' => ['web', 'auth'],
    ],
    function () {
        // Applyform
        Route::prefix('applyform')->name('applyform')->group(function () {
            Route::get('/', [ApplyformController::class, 'index'])->name('.index');
            Route::get('/noproject', [ApplyformController::class, 'noproject'])->name('.noproject');
        });

        // Route::resource('applyform', ApplyformController::class);

        // Applications
        Route::resource('applications', ApplicationsController::class);
        Route::put('applications/{id}/updateStatus', [ApplicationsController::class, 'updateStatus'])
            ->name('applications.updateStatus');
        Route::get('applications/view/claim/{id}', [ApplicationsController::class, 'viewEach'])->name('applications.viewEach');
        Route::put('applications/{id}', [ApplicationsController::class, 'update'])
            ->name('applications.update');
        Route::get('/applications/dates', [\Portal\Mileage\Http\Controllers\ApplicationsController::class, 'getClaimDates'])
            ->name('mileage::applications.getDates');

        // Project Manager
        Route::prefix('projectManager')->name('projectManager')->group(function () {
            Route::get('/', [ProjectManagerController::class, 'index'])->name('.index'); 
            Route::get('/show/{projectId}/{userId}', [ProjectManagerController::class, 'show'])->name('.show');            
            Route::post('/approve-month', [ProjectManagerController::class, 'approveMonth'])->name('.approveMonth');
            Route::post('/reject-month', [ProjectManagerController::class, 'rejectMonth'])->name('.rejectMonth');
        });

        // Project Director
        Route::prefix('projectDirector')->name('projectDirector')->group(function () {
            Route::get('/dashboard', [ProjectDirectorController::class, 'index'])->name('.index');
            Route::get('/show/{projectId}/{userId}', [ProjectDirectorController::class, 'show'])->name('.show');            
            Route::post('/approve-month', [ProjectDirectorController::class, 'approveMonth'])->name('.approveMonth');
            Route::post('/reject-month', [ProjectDirectorController::class, 'rejectMonth'])->name('.rejectMonth');
        });

        // Finance Department
        Route::prefix('finance')->name('finance')->group(function () {
            Route::get('/dashboard', [FinanceController::class, 'index'])->name('.index');
            Route::get('/show/{userId}', [FinanceController::class, 'show'])->name('.show');
            Route::put('/finance/update/{id}', [FinanceController::class, 'update'])->name('.update');
            Route::get('/view/claim/{id}', [FinanceController::class, 'viewEach'])->name('.viewEach');
            Route::put('/finance/claims/{id}/update-status', [FinanceController::class, 'updateStatus'])->name('.updateStatus');
            Route::post('/{id}/review', [FinanceController::class, 'review'])->name('.review'); 
            Route::post('/{id}/reject', [FinanceController::class, 'reject'])->name('.reject');
            Route::get('/export', [FinanceController::class, 'export'])->name('.export');
       
        });

        // HOD
        Route::prefix('HOD')->name('HOD')->group(function () {
            Route::get('/dashboard', [HODController::class, 'index'])->name('.index');
            Route::get('/show/{id}', [HODController::class, 'show'])->name('.show');
            Route::post('/{id}/verify', [HODController::class, 'verify'])->name('.verify');
            Route::post('/{id}/reject', [HODController::class, 'reject'])->name('.reject');        
        });

        // BOD
        Route::prefix('BOD')->name('BOD')->group(function () {
            Route::get('/dashboard', [BODController::class, 'index'])->name('.index');
            Route::get('/show/{id}', [BODController::class, 'show'])->name('.show');
            Route::post('/{id}/review', [BODController::class, 'approve'])->name('.approve');  
            Route::post('/{id}/reject', [BODController::class, 'reject'])->name('.reject');
        });

        // HR
        Route::prefix('HR')->name('HR')->group(function () {
            Route::get('/dashboard', [HRController::class, 'index'])->name('.index');
            Route::get('/show/{userId}', [HRController::class, 'show'])->name('.show');
            Route::get('/view/claim/{id}', [HRController::class, 'viewEach'])->name('.viewEach');
            Route::post('/{id}/reject', [HRController::class, 'reject'])->name('.reject');
            Route::get('/export', [HRController::class, 'export'])->name('.export');
        });
    }
);

// Guest group (currently unused)
Route::group(
    [
        'prefix'     => '',
        'as'         => 'mileage::',
        'middleware' => ['guest'],
    ],
    function () {
        //
    }
);
