<?php

use App\Http\Controllers\AccountController;
use App\Http\Controllers\Epelcon\BookingController;
use App\Http\Controllers\Epelcon\CustomerController;
use App\Http\Controllers\Epelcon\DashboardController;
use App\Http\Controllers\Epelcon\ExpenseController;
use App\Http\Controllers\Epelcon\FinanceController;
use App\Http\Controllers\Epelcon\HousekeepingController;
use App\Http\Controllers\Epelcon\InventoryController;
use App\Http\Controllers\Epelcon\MembershipController;
use App\Http\Controllers\Epelcon\MenuController;
use App\Http\Controllers\Epelcon\OrderController;
use App\Http\Controllers\Epelcon\ProcurementController;
use App\Http\Controllers\Epelcon\RoomController;
use App\Http\Controllers\Epelcon\StaffController;
use App\Http\Controllers\Epelcon\VendorController;
use App\Http\Controllers\PublicController;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Public guest website
|--------------------------------------------------------------------------
*/

Route::get('/', [PublicController::class, 'home'])->name('home');
Route::get('/rooms', [PublicController::class, 'rooms'])->name('site.rooms');
Route::get('/rooms/{roomType:slug}', [PublicController::class, 'roomType'])->name('site.room_type');
Route::get('/dining', [PublicController::class, 'dining'])->name('site.dining');
Route::get('/chefs', [PublicController::class, 'chefs'])->name('site.chefs');
Route::get('/dietary-plans', [PublicController::class, 'dietaryPlans'])->name('site.dietary_plans');
Route::get('/book', [PublicController::class, 'bookForm'])->name('site.book');
Route::post('/book', [PublicController::class, 'bookSubmit'])->name('site.book.submit');
Route::get('/order', [PublicController::class, 'orderForm'])->name('site.order');
Route::post('/order', [PublicController::class, 'orderSubmit'])->name('site.order.submit');
Route::get('/membership', [PublicController::class, 'membership'])->name('site.membership');
Route::get('/partners', [PublicController::class, 'partners'])->name('site.partners');
Route::post('/partners/apply', [PublicController::class, 'partnerApply'])->name('site.partners.apply');
Route::get('/contact', [PublicController::class, 'contact'])->name('site.contact');

// Online payments (Paystack / Flutterwave)
Route::get('/pay/callback/{gateway}', [App\Http\Controllers\PayController::class, 'callback'])->name('pay.callback');
Route::get('/pay/{type}/{code}', [App\Http\Controllers\PayController::class, 'show'])->name('pay.show');
Route::post('/pay/{type}/{code}', [App\Http\Controllers\PayController::class, 'init'])->name('pay.init');

// Guest reviews (post-checkout)
Route::get('/review/{code}', [App\Http\Controllers\ReviewController::class, 'create'])->name('review.create');
Route::post('/review/{code}', [App\Http\Controllers\ReviewController::class, 'store'])->name('review.store');

// Experiences (spa, pool, banquet…) + front pages
Route::get('/experiences', [App\Http\Controllers\SiteExperienceController::class, 'index'])->name('site.experiences');
Route::post('/experiences/book', [App\Http\Controllers\SiteExperienceController::class, 'book'])->name('site.experiences.book');
Route::get('/about-us', [App\Http\Controllers\SitePageController::class, 'about'])->name('site.about');
Route::get('/privacy-policy', [App\Http\Controllers\SitePageController::class, 'privacy'])->name('site.privacy');
Route::get('/terms', [App\Http\Controllers\SitePageController::class, 'terms'])->name('site.terms');

// Blog (public)
Route::get('/blog', [App\Http\Controllers\BlogController::class, 'index'])->name('site.blog.index');
Route::get('/blog/{post:slug}', [App\Http\Controllers\BlogController::class, 'show'])->name('site.blog.show');

// Community lounge (public chat)
Route::get('/community', [App\Http\Controllers\CommunityController::class, 'lounge'])->name('site.chat.lounge');
Route::post('/community/post', [App\Http\Controllers\CommunityController::class, 'post'])->name('site.chat.post');
Route::get('/api/community/messages', [App\Http\Controllers\CommunityController::class, 'feed'])->name('api.community.messages');

// Vendor marketplace (public profiles + spaces)
Route::get('/marketplace', [App\Http\Controllers\VendorPublicController::class, 'index'])->name('site.vendors.index');
Route::get('/marketplace/{vendor:slug}', [App\Http\Controllers\VendorPublicController::class, 'show'])->name('site.vendors.show');

// Catering & bulk orders (public)
Route::get('/catering', [App\Http\Controllers\CateringController::class, 'index'])->name('site.catering');
Route::post('/catering/order', [App\Http\Controllers\CateringController::class, 'order'])->name('site.catering.order');

// Two-factor authentication
Route::middleware('auth')->group(function () {
    Route::get('/2fa/setup', [App\Http\Controllers\Auth\TwoFactorController::class, 'setup'])->name('2fa.setup');
    Route::post('/2fa/confirm', [App\Http\Controllers\Auth\TwoFactorController::class, 'confirm'])->name('2fa.confirm');
    Route::post('/2fa/disable', [App\Http\Controllers\Auth\TwoFactorController::class, 'disable'])->name('2fa.disable');
    Route::get('/2fa/recovery-codes', [App\Http\Controllers\Auth\TwoFactorController::class, 'recoveryCodes'])->name('2fa.recovery');
    Route::post('/2fa/recovery-codes', [App\Http\Controllers\Auth\TwoFactorController::class, 'regenerateCodes'])->name('2fa.recovery.regenerate');
});
Route::get('/2fa/challenge', [App\Http\Controllers\Auth\TwoFactorController::class, 'challenge'])->name('2fa.challenge');
Route::post('/2fa/verify', [App\Http\Controllers\Auth\TwoFactorController::class, 'verify'])->name('2fa.verify');

Auth::routes(['verify' => false]);

/*
|--------------------------------------------------------------------------
| Customer / member portal
|--------------------------------------------------------------------------
*/

Route::prefix('account')->middleware('auth')->name('account.')->group(function () {
    Route::get('/', [AccountController::class, 'dashboard'])->name('dashboard');
    Route::get('/bookings', [AccountController::class, 'bookings'])->name('bookings');
    Route::get('/orders', [AccountController::class, 'orders'])->name('orders');
    Route::get('/membership', [AccountController::class, 'membership'])->name('membership');
    Route::post('/membership/subscribe/{plan}', [AccountController::class, 'subscribe'])->name('membership.subscribe');
    Route::get('/rewards', [AccountController::class, 'rewards'])->name('rewards');
    Route::get('/profile', [AccountController::class, 'profile'])->name('profile');
    Route::post('/profile', [AccountController::class, 'updateProfile'])->name('profile.update');
});

/*
|--------------------------------------------------------------------------
| Epelcon staff portal
|--------------------------------------------------------------------------
*/

// Subscription billing for hotel admins — reachable even when the portal is locked
Route::prefix('epelcon')->middleware(['auth', 'role:admin'])->name('epelcon.')->group(function () {
    Route::get('/billing', [App\Http\Controllers\Epelcon\BillingController::class, 'index'])->name('billing');
    Route::post('/billing/pay/{invoice}', [App\Http\Controllers\Epelcon\BillingController::class, 'pay'])->name('billing.pay');
});
Route::get('/billing/callback', [App\Http\Controllers\Epelcon\BillingController::class, 'callback'])
    ->middleware('auth')->name('billing.callback');

Route::prefix('epelcon')->middleware(['auth', 'role:staff', 'hotel.active'])->name('epelcon.')->group(function () {

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

    // Reception: bookings & reservations
    Route::middleware('role:manager,supervisor,receptionist')->group(function () {
        Route::get('/bookings', [BookingController::class, 'index'])->name('bookings.index');
        Route::get('/bookings/calendar', [BookingController::class, 'calendar'])->name('bookings.calendar');
        Route::post('/bookings', [BookingController::class, 'store'])->name('bookings.store');
        Route::get('/bookings/{booking}', [BookingController::class, 'show'])->name('bookings.show');
        Route::post('/bookings/{booking}/update', [BookingController::class, 'update'])->name('bookings.update');
        Route::post('/bookings/{booking}/status', [BookingController::class, 'setStatus'])->name('bookings.status');
        Route::post('/bookings/{booking}/check-in', [BookingController::class, 'checkIn'])->name('bookings.checkin');
        Route::post('/bookings/{booking}/check-out', [BookingController::class, 'checkOut'])->name('bookings.checkout');
        Route::post('/bookings/{booking}/payment', [BookingController::class, 'recordPayment'])->name('bookings.payment');
    });

    // Rooms & room types
    Route::middleware('role:manager,supervisor,receptionist,housekeeper')->group(function () {
        Route::get('/rooms', [RoomController::class, 'index'])->name('rooms.index');
    });
    Route::middleware('role:manager')->group(function () {
        Route::post('/rooms', [RoomController::class, 'store'])->name('rooms.store');
        Route::post('/rooms/{room}/update', [RoomController::class, 'update'])->name('rooms.update');
        Route::post('/rooms/{room}/delete', [RoomController::class, 'destroy'])->name('rooms.destroy');
        Route::post('/room-types', [RoomController::class, 'storeType'])->name('room_types.store');
        Route::post('/room-types/{roomType}/update', [RoomController::class, 'updateType'])->name('room_types.update');
    });
    Route::post('/rooms/{room}/housekeeping-status', [RoomController::class, 'setHousekeepingStatus'])
        ->middleware('role:manager,supervisor,housekeeper,receptionist')->name('rooms.hk_status');

    // Housekeeping (incl. self clock-in / clock-out timing)
    Route::middleware('role:manager,supervisor,housekeeper')->group(function () {
        Route::get('/housekeeping', [HousekeepingController::class, 'index'])->name('housekeeping.index');
        Route::post('/housekeeping', [HousekeepingController::class, 'store'])->name('housekeeping.store');
        Route::post('/housekeeping/{task}/status', [HousekeepingController::class, 'setStatus'])->name('housekeeping.status');
        Route::post('/housekeeping/{task}/clock-in', [HousekeepingController::class, 'clockIn'])->name('housekeeping.clockin');
        Route::post('/housekeeping/{task}/clock-out', [HousekeepingController::class, 'clockOut'])->name('housekeeping.clockout');
        Route::post('/housekeeping/{task}/delete', [HousekeepingController::class, 'destroy'])->name('housekeeping.destroy');
    });

    // Menu management: cuisines, categories, items, dietary plans, chefs
    Route::middleware('role:manager,chef,supervisor')->group(function () {
        Route::get('/menu', [MenuController::class, 'index'])->name('menu.index');
        Route::post('/menu/items', [MenuController::class, 'storeItem'])->name('menu.items.store');
        Route::post('/menu/items/{item}/update', [MenuController::class, 'updateItem'])->name('menu.items.update');
        Route::post('/menu/items/{item}/toggle', [MenuController::class, 'toggleItem'])->name('menu.items.toggle');
        Route::post('/menu/items/{item}/delete', [MenuController::class, 'destroyItem'])->name('menu.items.destroy');
        Route::post('/menu/cuisines', [MenuController::class, 'storeCuisine'])->name('menu.cuisines.store');
        Route::post('/menu/cuisines/{cuisine}/update', [MenuController::class, 'updateCuisine'])->name('menu.cuisines.update');
        Route::post('/menu/categories', [MenuController::class, 'storeCategory'])->name('menu.categories.store');
        Route::get('/chefs', [MenuController::class, 'chefs'])->name('chefs.index');
        Route::post('/chefs', [MenuController::class, 'storeChef'])->name('chefs.store');
        Route::post('/chefs/{chef}/update', [MenuController::class, 'updateChef'])->name('chefs.update');
        Route::get('/dietary-plans', [MenuController::class, 'dietaryPlans'])->name('dietary.index');
        Route::post('/dietary-plans', [MenuController::class, 'storeDietaryPlan'])->name('dietary.store');
        Route::post('/dietary-plans/{plan}/update', [MenuController::class, 'updateDietaryPlan'])->name('dietary.update');
    });

    // POS & orders: only front-of-house staff (waiters/bartenders/reception)
    // and management take orders. Housekeepers/chefs/kitchen are NOT here —
    // kitchen/chef see the Kitchen display; bartenders see the Bar display.
    Route::middleware('role:manager,supervisor,receptionist,waiter,bartender,accountant')->group(function () {
        Route::get('/orders', [OrderController::class, 'index'])->name('orders.index');
        Route::get('/pos', [OrderController::class, 'pos'])->name('orders.pos');
        Route::post('/orders', [OrderController::class, 'store'])->name('orders.store');
        Route::get('/orders/{order}', [OrderController::class, 'show'])->name('orders.show');
        Route::post('/orders/{order}/payment', [OrderController::class, 'recordPayment'])->name('orders.payment');
        Route::post('/orders/{order}/pickup', [OrderController::class, 'pickup'])->name('orders.pickup');
    });
    // Kitchen/chef/bartender accept orders (set ETA) and mark their items done
    Route::middleware('role:manager,supervisor,chef,kitchen,bartender,waiter')->group(function () {
        Route::post('/orders/{order}/accept', [OrderController::class, 'acceptStation'])->name('orders.accept');
        Route::post('/orders/{order}/status', [OrderController::class, 'setStatus'])->name('orders.status');
        Route::post('/orders/{order}/items/{item}/status', [OrderController::class, 'setItemStatus'])->name('orders.items.status');
    });

    // Guest reviews moderation & QR table ordering
    Route::middleware('role:manager,supervisor')->group(function () {
        Route::get('/reviews', [App\Http\Controllers\Epelcon\ReviewAdminController::class, 'index'])->name('reviews.index');
        Route::post('/reviews/{review}/status', [App\Http\Controllers\Epelcon\ReviewAdminController::class, 'setStatus'])->name('reviews.status');
        Route::get('/qr-codes', [App\Http\Controllers\Epelcon\QrController::class, 'index'])->name('qr.index');
    });

    // Kitchen display
    Route::get('/kitchen', [OrderController::class, 'kitchen'])
        ->middleware('role:manager,supervisor,chef,kitchen')->name('kitchen');

    // Kitchen stock & portions (kitchen staff + management). Specific paths
    // (/shift, /logs) declared before the /{item} wildcard.
    Route::middleware('role:manager,supervisor,chef,kitchen')->prefix('kitchen-stock')->name('kitchenstock.')->group(function () {
        Route::get('/', [App\Http\Controllers\Epelcon\KitchenStockController::class, 'index'])->name('index');
        Route::get('/shift', [App\Http\Controllers\Epelcon\KitchenStockController::class, 'shiftReport'])->name('shift');
        Route::get('/logs', [App\Http\Controllers\Epelcon\KitchenStockController::class, 'logs'])->name('logs');
        Route::post('/', [App\Http\Controllers\Epelcon\KitchenStockController::class, 'store'])->name('store');
        Route::post('/{item}/update', [App\Http\Controllers\Epelcon\KitchenStockController::class, 'update'])->name('update');
        Route::post('/{item}/adjust', [App\Http\Controllers\Epelcon\KitchenStockController::class, 'adjust'])->name('adjust');
    });

    // Catering & bulk package management
    Route::middleware('role:manager,supervisor,chef')->group(function () {
        Route::get('/catering', [App\Http\Controllers\Epelcon\CateringAdminController::class, 'index'])->name('catering.index');
        Route::post('/catering', [App\Http\Controllers\Epelcon\CateringAdminController::class, 'store'])->name('catering.store');
        Route::post('/catering/{package}/update', [App\Http\Controllers\Epelcon\CateringAdminController::class, 'update'])->name('catering.update');
        Route::post('/catering/{package}/toggle', [App\Http\Controllers\Epelcon\CateringAdminController::class, 'toggle'])->name('catering.toggle');
        Route::post('/catering/{package}/delete', [App\Http\Controllers\Epelcon\CateringAdminController::class, 'destroy'])->name('catering.destroy');
    });

    // Bar display
    Route::get('/bar', [OrderController::class, 'bar'])
        ->middleware('role:manager,supervisor,bartender')->name('bar');

    // Inventory
    Route::middleware('role:manager,supervisor,storekeeper,procurement')->group(function () {
        Route::get('/inventory', [InventoryController::class, 'index'])->name('inventory.index');
        Route::post('/inventory', [InventoryController::class, 'store'])->name('inventory.store');
        Route::post('/inventory/{item}/update', [InventoryController::class, 'update'])->name('inventory.update');
        Route::post('/inventory/{item}/movement', [InventoryController::class, 'recordMovement'])->name('inventory.movement');
        Route::get('/inventory/movements', [InventoryController::class, 'movements'])->name('inventory.movements');
    });

    // Procurement: suppliers & purchase orders
    Route::middleware('role:manager,procurement,storekeeper,accountant')->group(function () {
        Route::get('/procurement', [ProcurementController::class, 'index'])->name('procurement.index');
        Route::post('/procurement/suppliers', [ProcurementController::class, 'storeSupplier'])->name('procurement.suppliers.store');
        Route::post('/procurement/suppliers/{supplier}/update', [ProcurementController::class, 'updateSupplier'])->name('procurement.suppliers.update');
        Route::post('/procurement/orders', [ProcurementController::class, 'storeOrder'])->name('procurement.orders.store');
        Route::get('/procurement/orders/{purchaseOrder}', [ProcurementController::class, 'showOrder'])->name('procurement.orders.show');
        Route::post('/procurement/orders/{purchaseOrder}/status', [ProcurementController::class, 'setOrderStatus'])->name('procurement.orders.status');
    });

    // Expenses
    Route::middleware('role:manager,accountant,supervisor')->group(function () {
        Route::get('/expenses', [ExpenseController::class, 'index'])->name('expenses.index');
        Route::post('/expenses', [ExpenseController::class, 'store'])->name('expenses.store');
        Route::post('/expenses/{expense}/status', [ExpenseController::class, 'setStatus'])->name('expenses.status');
    });

    // Finance: sales, payments, reports
    Route::middleware('role:manager,accountant')->group(function () {
        Route::get('/finance', [FinanceController::class, 'index'])->name('finance.index');
        Route::get('/finance/payments', [FinanceController::class, 'payments'])->name('finance.payments');
    });

    // Customers / CRM
    Route::middleware('role:manager,supervisor,receptionist,accountant')->group(function () {
        Route::get('/customers', [CustomerController::class, 'index'])->name('customers.index');
        Route::post('/customers', [CustomerController::class, 'store'])->name('customers.store');
        Route::get('/customers/{customer}', [CustomerController::class, 'show'])->name('customers.show');
        Route::post('/customers/{customer}/update', [CustomerController::class, 'update'])->name('customers.update');
    });

    // Memberships, referrals & rewards
    Route::middleware('role:manager,receptionist,accountant')->group(function () {
        Route::get('/memberships', [MembershipController::class, 'index'])->name('memberships.index');
        Route::post('/memberships', [MembershipController::class, 'store'])->name('memberships.store');
        Route::post('/memberships/plans', [MembershipController::class, 'storePlan'])->name('memberships.plans.store');
        Route::post('/memberships/plans/{plan}/update', [MembershipController::class, 'updatePlan'])->name('memberships.plans.update');
        Route::get('/referrals', [MembershipController::class, 'referrals'])->name('referrals.index');
        Route::post('/rewards/adjust', [MembershipController::class, 'adjustPoints'])->name('rewards.adjust');
    });

    // Vendor marketplace + their bookable spaces
    Route::middleware('role:manager')->group(function () {
        Route::get('/vendors', [VendorController::class, 'index'])->name('vendors.index');
        Route::post('/vendors', [VendorController::class, 'store'])->name('vendors.store');
        Route::post('/vendors/{vendor}/update', [VendorController::class, 'update'])->name('vendors.update');
        Route::post('/vendors/{vendor}/status', [VendorController::class, 'setStatus'])->name('vendors.status');
        Route::get('/vendors/{vendor}/spaces', [VendorController::class, 'spaces'])->name('vendors.spaces');
        Route::post('/vendors/{vendor}/spaces', [VendorController::class, 'storeSpace'])->name('vendors.spaces.store');
        Route::post('/vendors/spaces/{space}/update', [VendorController::class, 'updateSpace'])->name('vendors.spaces.update');
        Route::post('/vendors/spaces/{space}/delete', [VendorController::class, 'deleteSpace'])->name('vendors.spaces.delete');
    });

    // HRMS: employees, attendance, leave, duty roster, loans, appraisals
    Route::prefix('hr')->middleware('role:manager,supervisor')->name('hr.')->group(function () {
        Route::get('/', [App\Http\Controllers\Epelcon\HrController::class, 'dashboard'])->name('dashboard');
        Route::get('/employees', [App\Http\Controllers\Epelcon\HrController::class, 'employees'])->name('employees');
        Route::post('/employees', [App\Http\Controllers\Epelcon\HrController::class, 'storeEmployee'])->name('employees.store');
        Route::post('/employees/{employee}/update', [App\Http\Controllers\Epelcon\HrController::class, 'updateEmployee'])->name('employees.update');
        Route::post('/departments', [App\Http\Controllers\Epelcon\HrController::class, 'storeDepartment'])->name('departments.store');
        Route::get('/attendance', [App\Http\Controllers\Epelcon\HrController::class, 'attendance'])->name('attendance');
        Route::post('/attendance', [App\Http\Controllers\Epelcon\HrController::class, 'markAttendance'])->name('attendance.mark');
        Route::get('/leave', [App\Http\Controllers\Epelcon\HrController::class, 'leave'])->name('leave');
        Route::post('/leave', [App\Http\Controllers\Epelcon\HrController::class, 'storeLeave'])->name('leave.store');
        Route::post('/leave/{leave}/status', [App\Http\Controllers\Epelcon\HrController::class, 'setLeaveStatus'])->name('leave.status');
        Route::get('/roster', [App\Http\Controllers\Epelcon\HrController::class, 'roster'])->name('roster');
        Route::post('/roster', [App\Http\Controllers\Epelcon\HrController::class, 'storeRoster'])->name('roster.store');
        Route::post('/shifts', [App\Http\Controllers\Epelcon\HrController::class, 'storeShift'])->name('shifts.store');
        Route::get('/loans', [App\Http\Controllers\Epelcon\HrController::class, 'loans'])->name('loans');
        Route::post('/loans', [App\Http\Controllers\Epelcon\HrController::class, 'storeLoan'])->name('loans.store');
        Route::post('/loans/{loan}/status', [App\Http\Controllers\Epelcon\HrController::class, 'setLoanStatus'])->name('loans.status');
        Route::get('/appraisals', [App\Http\Controllers\Epelcon\HrController::class, 'appraisals'])->name('appraisals');
        Route::post('/appraisals', [App\Http\Controllers\Epelcon\HrController::class, 'storeAppraisal'])->name('appraisals.store');
    });

    // Payroll
    Route::prefix('payroll')->middleware('role:manager,accountant')->name('payroll.')->group(function () {
        Route::get('/', [App\Http\Controllers\Epelcon\PayrollController::class, 'index'])->name('index');
        Route::post('/generate', [App\Http\Controllers\Epelcon\PayrollController::class, 'generate'])->name('generate');
        Route::get('/payslips', [App\Http\Controllers\Epelcon\PayrollController::class, 'payslips'])->name('payslips');
        Route::post('/payslips/{payslip}/paid', [App\Http\Controllers\Epelcon\PayrollController::class, 'markPaid'])->name('payslips.paid');
        Route::get('/payslips/{payslip}', [App\Http\Controllers\Epelcon\PayrollController::class, 'payslip'])->name('payslip');
        Route::get('/report', [App\Http\Controllers\Epelcon\PayrollController::class, 'report'])->name('report');
    });

    // Guest services (spa, pool, banquet…) & cab facility
    Route::middleware('role:manager,supervisor,receptionist')->group(function () {
        Route::get('/services', [App\Http\Controllers\Epelcon\ServiceController::class, 'index'])->name('services.index');
        Route::post('/services', [App\Http\Controllers\Epelcon\ServiceController::class, 'store'])->name('services.store');
        Route::post('/services/{service}/update', [App\Http\Controllers\Epelcon\ServiceController::class, 'update'])->name('services.update');
        Route::post('/services/{service}/toggle', [App\Http\Controllers\Epelcon\ServiceController::class, 'toggle'])->name('services.toggle');
        Route::get('/services/bookings', [App\Http\Controllers\Epelcon\ServiceController::class, 'bookings'])->name('services.bookings');
        Route::post('/services/bookings', [App\Http\Controllers\Epelcon\ServiceController::class, 'storeBooking'])->name('services.bookings.store');
        Route::post('/services/bookings/{serviceBooking}/status', [App\Http\Controllers\Epelcon\ServiceController::class, 'setBookingStatus'])->name('services.bookings.status');
        Route::post('/services/bookings/{serviceBooking}/paid', [App\Http\Controllers\Epelcon\ServiceController::class, 'markBookingPaid'])->name('services.bookings.paid');
        Route::get('/cabs', [App\Http\Controllers\Epelcon\CabController::class, 'index'])->name('cabs.index');
        Route::post('/cabs', [App\Http\Controllers\Epelcon\CabController::class, 'store'])->name('cabs.store');
        Route::post('/cabs/{cab}/update', [App\Http\Controllers\Epelcon\CabController::class, 'update'])->name('cabs.update');
        Route::post('/cabs/bookings', [App\Http\Controllers\Epelcon\CabController::class, 'storeBooking'])->name('cabs.bookings.store');
        Route::post('/cabs/bookings/{cabBooking}/status', [App\Http\Controllers\Epelcon\CabController::class, 'setBookingStatus'])->name('cabs.bookings.status');
    });

    // Blog / SEO content — manager writes, everyone reads-only
    Route::middleware('role:manager,supervisor')->group(function () {
        Route::get('/blog', [App\Http\Controllers\Epelcon\BlogAdminController::class, 'index'])->name('blog.index');
        Route::post('/blog', [App\Http\Controllers\Epelcon\BlogAdminController::class, 'storePost'])->name('blog.store');
        Route::get('/blog/{post}/edit', [App\Http\Controllers\Epelcon\BlogAdminController::class, 'editPost'])->name('blog.edit');
        Route::post('/blog/{post}/update', [App\Http\Controllers\Epelcon\BlogAdminController::class, 'updatePost'])->name('blog.update');
        Route::post('/blog/{post}/delete', [App\Http\Controllers\Epelcon\BlogAdminController::class, 'destroyPost'])->name('blog.destroy');
        Route::post('/blog/categories', [App\Http\Controllers\Epelcon\BlogAdminController::class, 'storeCategory'])->name('blog.categories.store');
        Route::post('/blog/categories/{category}/delete', [App\Http\Controllers\Epelcon\BlogAdminController::class, 'deleteCategory'])->name('blog.categories.delete');
    });

    // Room condition inspections — housekeepers + management
    // Amenity master (manager-only) MUST be declared before the {inspection}
    // wildcard so "amenities" isn't captured as an inspection id.
    Route::middleware('role:manager')->group(function () {
        Route::get('/inspections/amenities', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'amenities'])->name('inspections.amenities');
        Route::post('/inspections/amenities', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'storeAmenity'])->name('inspections.amenities.store');
        Route::post('/inspections/amenities/{amenity}/update', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'updateAmenity'])->name('inspections.amenities.update');
        Route::post('/inspections/amenities/{amenity}/delete', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'deleteAmenity'])->name('inspections.amenities.delete');
    });
    Route::middleware('role:manager,supervisor,housekeeper')->group(function () {
        Route::get('/inspections', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'index'])->name('inspections.index');
        Route::post('/inspections', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'start'])->name('inspections.start');
        Route::get('/inspections/{inspection}', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'show'])->name('inspections.show');
        Route::post('/inspections/{inspection}', [App\Http\Controllers\Epelcon\RoomInspectionController::class, 'update'])->name('inspections.update');
    });

    // Staff inbox — every staff role has an inbox for internal messaging
    Route::get('/inbox', [App\Http\Controllers\Epelcon\InboxController::class, 'index'])->name('inbox');
    Route::get('/inbox/{thread}', [App\Http\Controllers\Epelcon\InboxController::class, 'show'])->name('inbox.show');
    Route::post('/inbox', [App\Http\Controllers\Epelcon\InboxController::class, 'store'])->name('inbox.store');
    Route::post('/inbox/{thread}/reply', [App\Http\Controllers\Epelcon\InboxController::class, 'reply'])->name('inbox.reply');
    Route::post('/inbox/{thread}/read', [App\Http\Controllers\Epelcon\InboxController::class, 'markRead'])->name('inbox.read');
    Route::post('/inbox/announce', [App\Http\Controllers\Epelcon\InboxController::class, 'announce'])
        ->middleware('role:manager,admin')->name('inbox.announce');

    // Room settings, promo codes & reports
    Route::middleware('role:manager')->group(function () {
        Route::get('/room-settings', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'index'])->name('roomsettings');
        Route::post('/room-settings/beds', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'storeBed'])->name('roomsettings.beds.store');
        Route::post('/room-settings/beds/{bed}/delete', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'deleteBed'])->name('roomsettings.beds.delete');
        Route::post('/room-settings/booking-types', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'storeBookingType'])->name('roomsettings.btypes.store');
        Route::post('/room-settings/booking-types/{bookingType}/delete', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'deleteBookingType'])->name('roomsettings.btypes.delete');
        Route::post('/room-settings/complementary', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'storeComplementary'])->name('roomsettings.comp.store');
        Route::post('/room-settings/complementary/{item}/delete', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'deleteComplementary'])->name('roomsettings.comp.delete');
        Route::post('/room-settings/promos', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'storePromo'])->name('roomsettings.promos.store');
        Route::post('/room-settings/promos/{promo}/toggle', [App\Http\Controllers\Epelcon\RoomSettingsController::class, 'togglePromo'])->name('roomsettings.promos.toggle');
    });
    Route::middleware('role:manager,accountant,supervisor')->group(function () {
        Route::get('/reports/bookings', [App\Http\Controllers\Epelcon\ReportController::class, 'bookings'])->name('reports.bookings');
        Route::get('/reports/purchases', [App\Http\Controllers\Epelcon\ReportController::class, 'purchases'])->name('reports.purchases');
        Route::get('/reports/stock', [App\Http\Controllers\Epelcon\ReportController::class, 'stock'])->name('reports.stock');
    });

    // Staff management, security & settings (admin only; EnsureRole lets admin through)
    Route::middleware('role:admin')->group(function () {
        Route::get('/staff', [StaffController::class, 'index'])->name('staff.index');
        Route::post('/staff', [StaffController::class, 'store'])->name('staff.store');
        Route::post('/staff/{user}/update', [StaffController::class, 'update'])->name('staff.update');
        Route::post('/staff/{user}/toggle', [StaffController::class, 'toggle'])->name('staff.toggle');
        Route::get('/security', [StaffController::class, 'security'])->name('security.index');
        Route::get('/settings', [StaffController::class, 'settings'])->name('settings.index');
        Route::post('/settings', [StaffController::class, 'saveSettings'])->name('settings.save');
    });
});

/*
|--------------------------------------------------------------------------
| Platform owner console (multi-tenant SaaS management)
|--------------------------------------------------------------------------
*/

Route::prefix('platform')->middleware(['auth', 'role:super_admin'])->name('platform.')->group(function () {
    Route::get('/', [App\Http\Controllers\Platform\PlatformController::class, 'dashboard'])->name('dashboard');
    Route::get('/hotels', [App\Http\Controllers\Platform\PlatformController::class, 'hotels'])->name('hotels');
    Route::post('/hotels', [App\Http\Controllers\Platform\PlatformController::class, 'storeHotel'])->name('hotels.store');
    Route::post('/hotels/{hotel}/update', [App\Http\Controllers\Platform\PlatformController::class, 'updateHotel'])->name('hotels.update');
    Route::post('/hotels/{hotel}/status', [App\Http\Controllers\Platform\PlatformController::class, 'setHotelStatus'])->name('hotels.status');
    Route::get('/hotels/{hotel}/act-as', [App\Http\Controllers\Platform\PlatformController::class, 'actAs'])->name('act_as');
    Route::get('/stop-acting', [App\Http\Controllers\Platform\PlatformController::class, 'stopActing'])->name('stop_acting');
    Route::post('/plans', [App\Http\Controllers\Platform\PlatformController::class, 'storePlan'])->name('plans.store');
    Route::post('/plans/{plan}/update', [App\Http\Controllers\Platform\PlatformController::class, 'updatePlan'])->name('plans.update');
    Route::get('/invoices', [App\Http\Controllers\Platform\PlatformController::class, 'invoices'])->name('invoices');
    Route::post('/invoices/generate', [App\Http\Controllers\Platform\PlatformController::class, 'generateInvoice'])->name('invoices.generate');
    Route::post('/invoices/{invoice}/paid', [App\Http\Controllers\Platform\PlatformController::class, 'markInvoicePaid'])->name('invoices.paid');
});
