<?php

use App\Enums\Permission;
use App\Http\Controllers\Admin\Account\AppearanceController;
use App\Http\Controllers\Admin\Account\PasswordController;
use App\Http\Controllers\Admin\Account\PermissionsController;
use App\Http\Controllers\Admin\Account\ProfileController;
use App\Http\Controllers\Admin\AnalysisController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\Finance\CashController;
use App\Http\Controllers\Admin\Finance\EmployeeAdvanceController;
use App\Http\Controllers\Admin\Finance\ExpenseController;
use App\Http\Controllers\Admin\Finance\PayrollController;
use App\Http\Controllers\Admin\Hr\AttendanceController;
use App\Http\Controllers\Admin\Hr\EmployeeController;
use App\Http\Controllers\Admin\Hr\LeaveRequestController;
use App\Http\Controllers\Admin\Manage\Cutting\CuttingController;
use App\Http\Controllers\Admin\Manage\Cutting\CuttingDraftItemController;
use App\Http\Controllers\Admin\Manage\Order\OrderController;
use App\Http\Controllers\Admin\Manage\Order\OrderDraftItemController;
use App\Http\Controllers\Admin\Manage\OwnerVerificationController;
use App\Http\Controllers\Admin\Manage\Purchase\PurchaseController;
use App\Http\Controllers\Admin\Manage\Purchase\PurchaseDraftItemController;
use App\Http\Controllers\Admin\Manage\Stock\RetailStockController;
use App\Http\Controllers\Admin\Manage\Stock\StockController;
use App\Http\Controllers\Admin\Manage\StokOpnameController;
use App\Http\Controllers\Admin\Master\CategoryController;
use App\Http\Controllers\Admin\Master\CustomerController;
use App\Http\Controllers\Admin\Master\ProductController;
use App\Http\Controllers\Admin\Master\RawMaterialController;
use App\Http\Controllers\Admin\Master\SupplierController;
use App\Http\Controllers\Admin\NotificationController;
use App\Http\Controllers\Admin\System\ActivityLogController;
use App\Http\Controllers\Admin\System\RoleController;
use App\Http\Controllers\Admin\System\SettingController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\LogoutController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\PushSubscriptionController;
use Illuminate\Support\Facades\Route;

Route::get('/', [HomeController::class, 'index'])->name('home');

Route::middleware('guest')->group(function () {
    Route::get('/auth/login', [LoginController::class, 'index'])->name('login');
    Route::post('/auth/login', [LoginController::class, 'store']);
});

Route::middleware(['auth', 'permission:'.Permission::DASHBOARD_VIEW->value])->group(function () {
    Route::post('/auth/logout', [LogoutController::class, 'store'])->name('logout');

    // Push Notifications
    Route::post('/push-subscriptions', [PushSubscriptionController::class, 'store'])->name('push_subscriptions.store');
    Route::delete('/push-subscriptions', [PushSubscriptionController::class, 'destroy'])->name('push_subscriptions.destroy');

    // Notifications
    Route::get('/notifications', [NotificationController::class, 'index'])->name('notifications.index');
    Route::patch('/notifications/{notification}/read', [NotificationController::class, 'markAsRead'])->name('notifications.read');
    Route::patch('/notifications/read-all', [NotificationController::class, 'markAllAsRead'])->name('notifications.read_all');
    Route::delete('/notifications/{notification}', [NotificationController::class, 'destroy'])->name('notifications.destroy');
    Route::delete('/notifications', [NotificationController::class, 'destroyAll'])->name('notifications.destroy_all');

    Route::prefix('admin')->name('admin.')->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'index'])
            ->name('dashboard');

        Route::get('/analysis', [AnalysisController::class, 'index'])
            ->middleware('permission:'.Permission::ANALYSIS_VIEW->value)
            ->name('analysis');

        Route::prefix('master')->name('master.')->group(function () {
            Route::prefix('categories')->name('categories.')
                ->middleware('permission:'.Permission::CATEGORIES_VIEW->value)
                ->group(function () {
                    Route::get('/', [CategoryController::class, 'index'])->name('index');

                    Route::post('/', [CategoryController::class, 'store'])
                        ->middleware('permission:'.Permission::CATEGORIES_CREATE->value)
                        ->name('store');

                    Route::put('{category}', [CategoryController::class, 'update'])
                        ->middleware('permission:'.Permission::CATEGORIES_UPDATE->value)
                        ->name('update');

                    Route::delete('{category}', [CategoryController::class, 'destroy'])
                        ->middleware('permission:'.Permission::CATEGORIES_DELETE->value)
                        ->name('destroy');
                });

            Route::prefix('products')->name('products.')
                ->middleware('permission:'.Permission::PRODUCTS_VIEW->value)
                ->group(function () {
                    Route::get('create', [ProductController::class, 'create'])
                        ->middleware('permission:'.Permission::PRODUCTS_CREATE->value)
                        ->name('create');

                    Route::post('/', [ProductController::class, 'store'])
                        ->middleware('permission:'.Permission::PRODUCTS_CREATE->value)
                        ->name('store');

                    Route::get('{product}/edit', [ProductController::class, 'edit'])
                        ->middleware([
                            'permission:'.Permission::PRODUCTS_UPDATE->value,
                            'no_pending_owner_verification:product',
                        ])
                        ->name('edit');

                    Route::put('{product}', [ProductController::class, 'update'])
                        ->middleware([
                            'permission:'.Permission::PRODUCTS_UPDATE->value,
                            'no_pending_owner_verification:product',
                        ])
                        ->name('update');

                    Route::patch('{product}/toggle-status', [ProductController::class, 'toggleStatus'])
                        ->middleware([
                            'permission:'.Permission::PRODUCTS_TOGGLE_STATUS->value,
                            'no_pending_owner_verification:product',
                        ])
                        ->name('toggle_status');

                    Route::delete('{product}', [ProductController::class, 'destroy'])
                        ->middleware([
                            'permission:'.Permission::PRODUCTS_DELETE->value,
                            'no_pending_owner_verification:product',
                        ])
                        ->name('destroy');

                    Route::get('/', [ProductController::class, 'index'])->name('index');
                });

            Route::prefix('raw-materials')->name('raw_materials.')
                ->middleware('permission:'.Permission::RAW_MATERIALS_VIEW->value)
                ->group(function () {
                    Route::get('create', [RawMaterialController::class, 'create'])
                        ->middleware('permission:'.Permission::RAW_MATERIALS_CREATE->value)
                        ->name('create');

                    Route::post('/', [RawMaterialController::class, 'store'])
                        ->middleware('permission:'.Permission::RAW_MATERIALS_CREATE->value)
                        ->name('store');

                    Route::get('{rawMaterial}/edit', [RawMaterialController::class, 'edit'])
                        ->middleware([
                            'permission:'.Permission::RAW_MATERIALS_UPDATE->value,
                            'no_pending_owner_verification:rawMaterial',
                        ])
                        ->name('edit');

                    Route::put('{rawMaterial}', [RawMaterialController::class, 'update'])
                        ->middleware([
                            'permission:'.Permission::RAW_MATERIALS_UPDATE->value,
                            'no_pending_owner_verification:rawMaterial',
                        ])
                        ->name('update');

                    Route::patch('{rawMaterial}/toggle-status', [RawMaterialController::class, 'toggleStatus'])
                        ->middleware([
                            'permission:'.Permission::RAW_MATERIALS_TOGGLE_STATUS->value,
                            'no_pending_owner_verification:rawMaterial',
                        ])
                        ->name('toggle_status');

                    Route::delete('{rawMaterial}', [RawMaterialController::class, 'destroy'])
                        ->middleware([
                            'permission:'.Permission::RAW_MATERIALS_DELETE->value,
                            'no_pending_owner_verification:rawMaterial',
                        ])
                        ->name('destroy');

                    Route::get('/', [RawMaterialController::class, 'index'])->name('index');
                });

            Route::prefix('suppliers')->name('suppliers.')
                ->middleware('permission:'.Permission::SUPPLIERS_VIEW->value)
                ->group(function () {
                    Route::get('/', [SupplierController::class, 'index'])->name('index');

                    Route::post('/', [SupplierController::class, 'store'])
                        ->middleware('permission:'.Permission::SUPPLIERS_CREATE->value)
                        ->name('store');

                    Route::put('{supplier}', [SupplierController::class, 'update'])
                        ->middleware('permission:'.Permission::SUPPLIERS_UPDATE->value)
                        ->name('update');

                    Route::delete('{supplier}', [SupplierController::class, 'destroy'])
                        ->middleware('permission:'.Permission::SUPPLIERS_DELETE->value)
                        ->name('destroy');
                });

            Route::prefix('customers')->name('customers.')
                ->middleware('permission:'.Permission::CUSTOMERS_VIEW->value)
                ->group(function () {
                    Route::get('/', [CustomerController::class, 'index'])->name('index');

                    Route::post('/', [CustomerController::class, 'store'])
                        ->middleware('permission:'.Permission::CUSTOMERS_CREATE->value)
                        ->name('store');

                    Route::post('api', [CustomerController::class, 'storeApi'])
                        ->middleware('permission:'.Permission::CUSTOMERS_CREATE->value)
                        ->name('store.api');

                    Route::put('{customer}', [CustomerController::class, 'update'])
                        ->middleware('permission:'.Permission::CUSTOMERS_UPDATE->value)
                        ->name('update');

                    Route::delete('{customer}', [CustomerController::class, 'destroy'])
                        ->middleware('permission:'.Permission::CUSTOMERS_DELETE->value)
                        ->name('destroy');
                });

        });

        Route::prefix('manage')->name('manage.')->group(function () {
            Route::prefix('purchases')->name('purchases.')
                ->middleware('permission:'.Permission::PURCHASES_VIEW->value)
                ->group(function () {
                    Route::get('/', [PurchaseController::class, 'index'])->name('index');

                    Route::get('create', [PurchaseController::class, 'create'])
                        ->middleware('permission:'.Permission::PURCHASES_CREATE->value)
                        ->name('create');

                    Route::post('draft-items', [PurchaseDraftItemController::class, 'store'])
                        ->middleware('permission:'.Permission::PURCHASES_CREATE->value)
                        ->name('draft_items.store');

                    Route::post('draft-items/new-variant', [PurchaseDraftItemController::class, 'storeNewVariant'])
                        ->middleware('permission:'.Permission::PURCHASES_CREATE->value)
                        ->name('draft_items.store_new_variant');

                    Route::delete('draft-items/{rawMaterialPrice}', [PurchaseDraftItemController::class, 'destroy'])
                        ->middleware('permission:'.Permission::PURCHASES_CREATE->value)
                        ->name('draft_items.destroy');

                    Route::post('/', [PurchaseController::class, 'store'])
                        ->middleware('permission:'.Permission::PURCHASES_CREATE->value)
                        ->name('store');

                    Route::get('{purchase}/edit', [PurchaseController::class, 'edit'])
                        ->middleware([
                            'permission:'.Permission::PURCHASES_UPDATE->value,
                            'no_pending_owner_verification:purchase',
                        ])
                        ->name('edit');

                    Route::put('{purchase}', [PurchaseController::class, 'update'])
                        ->middleware([
                            'permission:'.Permission::PURCHASES_UPDATE->value,
                            'no_pending_owner_verification:purchase',
                        ])
                        ->name('update');

                    Route::delete('{purchase}', [PurchaseController::class, 'destroy'])
                        ->middleware([
                            'permission:'.Permission::PURCHASES_DELETE->value,
                            'no_pending_owner_verification:purchase',
                        ])
                        ->name('destroy');
                });

            Route::prefix('orders')->name('orders.')
                ->middleware('permission:'.Permission::ORDERS_VIEW->value)
                ->group(function () {
                    Route::get('/', [OrderController::class, 'index'])->name('index');

                    Route::get('create', [OrderController::class, 'create'])
                        ->middleware('permission:'.Permission::ORDERS_CREATE->value)
                        ->name('create');

                    Route::post('draft-items', [OrderDraftItemController::class, 'store'])
                        ->middleware('permission:'.Permission::ORDERS_CREATE->value)
                        ->name('draft_items.store');

                    Route::put('draft-items/resync-prices', [OrderDraftItemController::class, 'resyncPrices'])
                        ->middleware('permission:'.Permission::ORDERS_CREATE->value)
                        ->name('draft_items.resync_prices');

                    Route::delete('draft-items/{productVariant}', [OrderDraftItemController::class, 'destroy'])
                        ->middleware('permission:'.Permission::ORDERS_CREATE->value)
                        ->name('draft_items.destroy');

                    Route::post('/', [OrderController::class, 'store'])
                        ->middleware('permission:'.Permission::ORDERS_CREATE->value)
                        ->name('store');

                    Route::get('{order}', [OrderController::class, 'show'])->name('show');

                    Route::get('{order}/edit', [OrderController::class, 'edit'])
                        ->middleware('permission:'.Permission::ORDERS_UPDATE->value)
                        ->name('edit');

                    Route::put('{order}', [OrderController::class, 'update'])
                        ->middleware('permission:'.Permission::ORDERS_UPDATE->value)
                        ->name('update');

                    Route::post('{order}/status', [OrderController::class, 'transitionStatus'])
                        ->name('transition_status');

                    Route::delete('{order}', [OrderController::class, 'destroy'])
                        ->middleware('permission:'.Permission::ORDERS_DELETE->value)
                        ->name('destroy');
                });

            Route::prefix('cuttings')->name('cuttings.')
                ->group(function () {
                    Route::get('/', [CuttingController::class, 'index'])
                        ->middleware('permission:'.Permission::CUTTINGS_VIEW->value)
                        ->name('index');

                    Route::get('create', [CuttingController::class, 'create'])
                        ->middleware('permission:'.Permission::CUTTINGS_VIEW->value.'|'.Permission::CUTTINGS_CREATE->value)
                        ->name('create');

                    Route::post('draft-materials', [CuttingDraftItemController::class, 'storeMaterial'])
                        ->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
                        ->name('draft_materials.store');

                    Route::delete('draft-materials/{rawMaterialPrice}', [CuttingDraftItemController::class, 'destroyMaterial'])
                        ->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
                        ->name('draft_materials.destroy');

                    Route::post('draft-results', [CuttingDraftItemController::class, 'storeResult'])
                        ->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
                        ->name('draft_results.store');

                    Route::delete('draft-results/{productVariant}', [CuttingDraftItemController::class, 'destroyResult'])
                        ->middleware('permission:'.Permission::CUTTINGS_CREATE->value)
                        ->name('draft_results.destroy');

                    Route::post('/', [CuttingController::class, 'store'])
                        ->middleware('permission:'.Permission::CUTTINGS_VIEW->value.'|'.Permission::CUTTINGS_CREATE->value)
                        ->name('store');

                    Route::get('{cutting}/edit', [CuttingController::class, 'edit'])
                        ->middleware('permission:'.Permission::CUTTINGS_VIEW->value.'|'.Permission::CUTTINGS_UPDATE->value)
                        ->name('edit');

                    Route::put('{cutting}', [CuttingController::class, 'update'])
                        ->middleware('permission:'.Permission::CUTTINGS_VIEW->value.'|'.Permission::CUTTINGS_UPDATE->value)
                        ->name('update');

                    Route::post('{cutting}/status', [CuttingController::class, 'transitionStatus'])
                        ->middleware('permission:'.Permission::CUTTINGS_COMPLETE->value.'|'.Permission::CUTTINGS_VERIFY->value.'|'.Permission::CUTTINGS_REJECT->value)
                        ->name('transition_status');

                    Route::delete('{cutting}', [CuttingController::class, 'destroy'])
                        ->middleware('permission:'.Permission::CUTTINGS_VIEW->value.'|'.Permission::CUTTINGS_DELETE->value)
                        ->name('destroy');
                });

            Route::prefix('stocks')->name('stocks.')
                ->middleware('permission:'.Permission::STOCKS_VIEW->value)
                ->group(function () {
                    Route::get('/', [StockController::class, 'index'])->name('index');

                    Route::post('{cutting}/verify', [StockController::class, 'verify'])
                        ->middleware('permission:'.Permission::CUTTINGS_VERIFY->value)
                        ->name('verify');
                });

            Route::prefix('retail-stock')->name('retail-stock.')
                ->middleware('permission:'.Permission::STOCKS_VIEW->value)
                ->group(function () {
                    Route::post('/transfer', [RetailStockController::class, 'transfer'])->name('transfer');
                });

            Route::prefix('stok-opnames')->name('stok-opnames.')
                ->middleware('permission:'.Permission::STOK_OPNAMES_VIEW->value)
                ->group(function () {
                    Route::get('/', [StokOpnameController::class, 'index'])->name('index');

                    Route::get('create', [StokOpnameController::class, 'create'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_CREATE->value)
                        ->name('create');

                    Route::post('/', [StokOpnameController::class, 'store'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_CREATE->value)
                        ->name('store');

                    Route::post('auto-save', [StokOpnameController::class, 'autoSave'])
                        ->name('auto_save');

                    Route::get('{stokOpname}/edit', [StokOpnameController::class, 'edit'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_UPDATE->value)
                        ->name('edit');

                    Route::put('{stokOpname}', [StokOpnameController::class, 'update'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_UPDATE->value)
                        ->name('update');

                    Route::delete('{stokOpname}', [StokOpnameController::class, 'destroy'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_DELETE->value)
                        ->name('destroy');

                    Route::post('{stokOpname}/submit', [StokOpnameController::class, 'submit'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_SUBMIT->value)
                        ->name('submit');

                    Route::post('{stokOpname}/verify', [StokOpnameController::class, 'verify'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_VERIFY->value)
                        ->name('verify');

                    Route::post('{stokOpname}/reject', [StokOpnameController::class, 'reject'])
                        ->middleware('permission:'.Permission::STOK_OPNAMES_VERIFY->value)
                        ->name('reject');
                });

            Route::prefix('owner-verifications')->name('owner_verifications.')
                ->group(function () {
                    Route::post('cuttings/{cutting}/approve', [OwnerVerificationController::class, 'approveCutting'])
                        ->middleware('permission:'.Permission::OWNER_VERIFICATIONS_VERIFY->value)
                        ->name('approve');

                    Route::post('cuttings/{cutting}/reject', [OwnerVerificationController::class, 'rejectCutting'])
                        ->middleware('permission:'.Permission::OWNER_VERIFICATIONS_REJECT->value)
                        ->name('reject');

                    Route::post('requests/{ownerVerificationRequest}/approve', [OwnerVerificationController::class, 'approveRequest'])
                        ->middleware('permission:'.Permission::OWNER_VERIFICATIONS_VERIFY->value)
                        ->name('approve_request');

                    Route::post('requests/{ownerVerificationRequest}/reject', [OwnerVerificationController::class, 'rejectRequest'])
                        ->middleware('permission:'.Permission::OWNER_VERIFICATIONS_REJECT->value)
                        ->name('reject_request');
                });
        });

        Route::prefix('system')->name('system.')->group(function () {
            Route::prefix('roles')->name('roles.')
                ->middleware('permission:'.Permission::ROLES_VIEW->value)
                ->group(function () {
                    Route::get('/', [RoleController::class, 'index'])->name('index');

                    Route::get('create', [RoleController::class, 'create'])
                        ->middleware('permission:'.Permission::ROLES_CREATE->value)
                        ->name('create');

                    Route::post('/', [RoleController::class, 'store'])
                        ->middleware('permission:'.Permission::ROLES_CREATE->value)
                        ->name('store');

                    Route::get('{role}/edit', [RoleController::class, 'edit'])
                        ->middleware('permission:'.Permission::ROLES_UPDATE->value)
                        ->name('edit');

                    Route::put('{role}', [RoleController::class, 'update'])
                        ->middleware('permission:'.Permission::ROLES_UPDATE->value)
                        ->name('update');

                    Route::delete('{role}', [RoleController::class, 'destroy'])
                        ->middleware('permission:'.Permission::ROLES_DELETE->value)
                        ->name('destroy');
                });

            Route::prefix('activity-logs')->name('activity_logs.')
                ->middleware('permission:'.Permission::ACTIVITY_LOGS_VIEW->value)
                ->group(function () {
                    Route::get('/', [ActivityLogController::class, 'index'])->name('index');
                });

            Route::prefix('settings')->name('settings.')
                ->middleware('permission:'.Permission::SETTINGS_VIEW->value)
                ->group(function () {
                    Route::get('/', [SettingController::class, 'index'])->name('index');

                    Route::put('system', [SettingController::class, 'updateSystem'])
                        ->middleware('permission:'.Permission::SETTINGS_UPDATE->value)
                        ->name('system.update');

                    Route::put('social-media', [SettingController::class, 'updateSocialMedia'])
                        ->middleware('permission:'.Permission::SETTINGS_UPDATE->value)
                        ->name('social_media.update');

                    Route::put('marketplace', [SettingController::class, 'updateMarketplace'])
                        ->middleware('permission:'.Permission::SETTINGS_UPDATE->value)
                        ->name('marketplace.update');

                    Route::put('hr', [SettingController::class, 'updateHr'])
                        ->middleware('permission:'.Permission::SETTINGS_UPDATE->value)
                        ->name('hr.update');

                    Route::put('homepage', [SettingController::class, 'updateHomepage'])
                        ->middleware('permission:'.Permission::SETTINGS_UPDATE->value)
                        ->name('homepage.update');
                });
        });

        Route::prefix('account')->name('account.')->group(function () {
            Route::get('profile', [ProfileController::class, 'edit'])->name('profile');
            Route::put('profile', [ProfileController::class, 'update'])->name('profile.update');

            Route::get('password', [PasswordController::class, 'edit'])->name('password');
            Route::put('password', [PasswordController::class, 'update'])->name('password.update');

            Route::get('appearance', [AppearanceController::class, 'edit'])->name('appearance');
            Route::put('appearance', [AppearanceController::class, 'update'])->name('appearance.update');

            Route::get('permissions', [PermissionsController::class, 'index'])->name('permissions');
        });

        Route::prefix('finance')->name('finance.')->group(function () {
            Route::prefix('cash')->name('cash.')
                ->middleware('permission:'.Permission::CASH_VIEW->value)
                ->group(function () {
                    Route::get('/', [CashController::class, 'index'])->name('index');

                    Route::post('deposit', [CashController::class, 'deposit'])
                        ->middleware('permission:'.Permission::CASH_DEPOSIT->value)
                        ->name('deposit');

                    Route::post('withdraw', [CashController::class, 'withdraw'])
                        ->middleware('permission:'.Permission::CASH_WITHDRAW->value)
                        ->name('withdraw');

                    Route::put('transactions/{cashTransaction}', [CashController::class, 'update'])
                        ->middleware('permission:'.Permission::CASH_UPDATE->value)
                        ->name('transactions.update');

                    Route::delete('transactions/{cashTransaction}', [CashController::class, 'destroy'])
                        ->middleware('permission:'.Permission::CASH_DELETE->value)
                        ->name('transactions.destroy');
                });

            Route::prefix('expenses')->name('expenses.')
                ->middleware('permission:'.Permission::EXPENSES_VIEW->value)
                ->group(function () {
                    Route::get('/', [ExpenseController::class, 'index'])->name('index');

                    Route::post('/', [ExpenseController::class, 'store'])
                        ->middleware('permission:'.Permission::EXPENSES_CREATE->value)
                        ->name('store');

                    Route::put('{expense}', [ExpenseController::class, 'update'])
                        ->middleware('permission:'.Permission::EXPENSES_UPDATE->value)
                        ->name('update');

                    Route::delete('{expense}', [ExpenseController::class, 'destroy'])
                        ->middleware('permission:'.Permission::EXPENSES_DELETE->value)
                        ->name('destroy');
                });

            Route::prefix('employee-advances')->name('employee_advances.')
                ->middleware('permission:'.Permission::EMPLOYEE_ADVANCES_VIEW->value)
                ->group(function () {
                    Route::get('/', [EmployeeAdvanceController::class, 'index'])->name('index');

                    Route::post('/', [EmployeeAdvanceController::class, 'store'])
                        ->middleware('permission:'.Permission::EMPLOYEE_ADVANCES_CREATE->value)
                        ->name('store');

                    Route::put('{employeeAdvance}', [EmployeeAdvanceController::class, 'update'])
                        ->middleware('permission:'.Permission::EMPLOYEE_ADVANCES_UPDATE->value)
                        ->name('update');

                    Route::delete('{employeeAdvance}', [EmployeeAdvanceController::class, 'destroy'])
                        ->middleware('permission:'.Permission::EMPLOYEE_ADVANCES_DELETE->value)
                        ->name('destroy');

                    Route::post('{employeeAdvance}/approve', [EmployeeAdvanceController::class, 'approve'])
                        ->middleware('permission:'.Permission::EMPLOYEE_ADVANCES_VERIFY->value)
                        ->name('approve');

                    Route::post('{employeeAdvance}/reject', [EmployeeAdvanceController::class, 'reject'])
                        ->middleware('permission:'.Permission::EMPLOYEE_ADVANCES_VERIFY->value)
                        ->name('reject');

                    Route::post('{employeeAdvance}/pay', [EmployeeAdvanceController::class, 'pay'])
                        ->middleware('permission:'.Permission::EMPLOYEE_ADVANCES_PAY->value)
                        ->name('pay');
                });

            Route::prefix('payroll')->name('payroll.')
                ->middleware('permission:'.Permission::PAYROLL_VIEW->value)
                ->group(function () {
                    Route::get('/', [PayrollController::class, 'index'])->name('index');

                    Route::post('{payroll}/adjustments', [PayrollController::class, 'storeAdjustment'])
                        ->middleware('permission:'.Permission::PAYROLL_ADJUST->value)
                        ->name('adjustments.store');

                    Route::put('adjustments/{payrollAdjustment}', [PayrollController::class, 'updateAdjustment'])
                        ->middleware('permission:'.Permission::PAYROLL_ADJUST->value)
                        ->name('adjustments.update');

                    Route::delete('adjustments/{payrollAdjustment}', [PayrollController::class, 'destroyAdjustment'])
                        ->middleware('permission:'.Permission::PAYROLL_ADJUST->value)
                        ->name('adjustments.destroy');
                });
        });

        Route::prefix('hr')->name('hr.')->group(function () {
            Route::prefix('attendances')->name('attendances.')
                ->middleware('permission:'.Permission::ATTENDANCES_VIEW->value)
                ->group(function () {
                    Route::get('/', [AttendanceController::class, 'index'])->name('index');

                    Route::post('check-in', [AttendanceController::class, 'checkIn'])
                        ->middleware('permission:'.Permission::ATTENDANCES_CREATE->value)
                        ->name('check_in');

                    Route::post('check-out', [AttendanceController::class, 'checkOut'])
                        ->middleware('permission:'.Permission::ATTENDANCES_CREATE->value)
                        ->name('check_out');

                    Route::delete('{attendance}', [AttendanceController::class, 'destroy'])
                        ->middleware('permission:'.Permission::ATTENDANCES_DELETE->value)
                        ->name('destroy');
                });

            Route::prefix('employees')->name('employees.')
                ->middleware('permission:'.Permission::EMPLOYEES_VIEW->value)
                ->group(function () {
                    Route::post('{user}/reset-password', [EmployeeController::class, 'resetPassword'])
                        ->middleware('permission:'.Permission::EMPLOYEES_RESET_PASSWORD->value)
                        ->name('reset_password');

                    Route::patch('{user}/toggle-status', [EmployeeController::class, 'toggleStatus'])
                        ->middleware('permission:'.Permission::EMPLOYEES_TOGGLE_STATUS->value)
                        ->name('toggle_status');

                    Route::get('create', [EmployeeController::class, 'create'])
                        ->middleware('permission:'.Permission::EMPLOYEES_CREATE->value)
                        ->name('create');

                    Route::post('/', [EmployeeController::class, 'store'])
                        ->middleware('permission:'.Permission::EMPLOYEES_CREATE->value)
                        ->name('store');

                    Route::get('{user}/edit', [EmployeeController::class, 'edit'])
                        ->middleware('permission:'.Permission::EMPLOYEES_UPDATE->value)
                        ->name('edit');

                    Route::put('{user}', [EmployeeController::class, 'update'])
                        ->middleware('permission:'.Permission::EMPLOYEES_UPDATE->value)
                        ->name('update');

                    Route::delete('{user}', [EmployeeController::class, 'destroy'])
                        ->middleware('permission:'.Permission::EMPLOYEES_DELETE->value)
                        ->name('destroy');

                    Route::get('/', [EmployeeController::class, 'index'])->name('index');
                });

            Route::prefix('leave-requests')->name('leave_requests.')
                ->middleware('permission:'.Permission::LEAVE_REQUESTS_VIEW->value)
                ->group(function () {
                    Route::get('/', [LeaveRequestController::class, 'index'])->name('index');

                    Route::post('/', [LeaveRequestController::class, 'store'])
                        ->middleware('permission:'.Permission::LEAVE_REQUESTS_CREATE->value)
                        ->name('store');

                    Route::put('{leaveRequest}', [LeaveRequestController::class, 'update'])
                        ->middleware('permission:'.Permission::LEAVE_REQUESTS_UPDATE->value)
                        ->name('update');

                    Route::delete('{leaveRequest}', [LeaveRequestController::class, 'destroy'])
                        ->middleware('permission:'.Permission::LEAVE_REQUESTS_DELETE->value)
                        ->name('destroy');

                    Route::post('{leaveRequest}/approve', [LeaveRequestController::class, 'approve'])
                        ->middleware('permission:'.Permission::LEAVE_REQUESTS_VERIFY->value)
                        ->name('approve');

                    Route::post('{leaveRequest}/reject', [LeaveRequestController::class, 'reject'])
                        ->middleware('permission:'.Permission::LEAVE_REQUESTS_VERIFY->value)
                        ->name('reject');
                });
        });
    });
});
