<?php

use App\Http\Controllers\AccountsController;
use App\Http\Controllers\AccountsExpensesController;
use App\Http\Controllers\AccountsMonthlySettlementController;
use App\Http\Controllers\AdController;
use App\Http\Controllers\AdsCreationController;
use App\Http\Controllers\AdSetController;
use App\Http\Controllers\AppDevelopmentController;
use App\Http\Controllers\CampaignController;
use App\Http\Controllers\ChatController;
use App\Http\Controllers\CustomersController;
use App\Http\Controllers\DomainsEmailsController;
use App\Http\Controllers\EmployeesController;
use App\Http\Controllers\FacebookIntegrationController;
use App\Http\Controllers\InventoryController;
use App\Http\Controllers\MainCategoryController;
use App\Http\Controllers\MonthlySubscriptionLimitedController;
use App\Http\Controllers\MonthlySubscriptionOpenController;
use App\Http\Controllers\NotesRemindersController;
use App\Http\Controllers\NotificationsController;
use App\Http\Controllers\OneTimeServiceController;
use App\Http\Controllers\OperationsController;
use App\Http\Controllers\POSController;
use App\Http\Controllers\ProductColorController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\ProductMeasurementController;
use App\Http\Controllers\ProductsHubController;
use App\Http\Controllers\ProductSizeController;
use App\Http\Controllers\RenewalsController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\SettingsController;
use App\Http\Controllers\StageAcademyBannerController;
use App\Http\Controllers\StageAcademyController;
use App\Http\Controllers\StageAcademyCourseCategoriesController;
use App\Http\Controllers\StageAcademyCoursesController;
use App\Http\Controllers\StageAcademyCoursesItemsController;
use App\Http\Controllers\StageAcademyCourseSubCategoriesController;
use App\Http\Controllers\StageAcademyInstitutionsController;
use App\Http\Controllers\StageAcademyOffersController;
use App\Http\Controllers\StageAcademyPortalController;
use App\Http\Controllers\StageAcademySettingsController;
use App\Http\Controllers\StageAcademyTrainersController;
use App\Http\Controllers\SubCategoryController;
use App\Http\Controllers\SystemAssistantAppointmentsController;
use App\Http\Controllers\SystemAssistantController;
use App\Http\Controllers\Web\Auth\LoginController;
use App\Http\Controllers\Web\LanguageController;
use App\Http\Controllers\Web\MarketingIntelligenceController;
use App\Http\Controllers\Web\NewsController;
use App\Http\Controllers\Web\PageController;
use App\Http\Controllers\Web\ProfileController;
use App\Http\Controllers\Web\TicketController;
use App\Http\Controllers\Web\TwoFactorController;
use App\Http\Controllers\WebDevelopmentController;
use App\Http\Controllers\WordPressController;
use App\Models\ServiceSubscription;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
    $file = base_path('static_site/index.html');

    abort_unless(File::exists($file), 404);

    return response(File::get($file), 200)->header('Content-Type', 'text/html; charset=UTF-8');
});

Route::get('/assets/{path}', function (string $path) {
    $file = realpath(base_path('static_site/assets/'.$path));
    $base = realpath(base_path('static_site/assets'));

    abort_unless($file && $base && str_starts_with($file, $base) && is_file($file), 404);

    $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
    $mime = match ($ext) {
        'css' => 'text/css; charset=UTF-8',
        'js' => 'application/javascript; charset=UTF-8',
        'png' => 'image/png',
        'jpg', 'jpeg' => 'image/jpeg',
        'gif' => 'image/gif',
        'svg' => 'image/svg+xml',
        'webp' => 'image/webp',
        default => File::mimeType($file) ?: 'application/octet-stream',
    };

    return response(File::get($file), 200)->header('Content-Type', $mime);
})->where('path', '.*');

Route::get('/works-apps.html', [SettingsController::class, 'publicAppsPage']);
Route::get('/ar/works-apps.html', fn () => app(SettingsController::class)->publicAppsPage('ar'));
Route::get('/ku/works-apps.html', fn () => app(SettingsController::class)->publicAppsPage('ku'));

Route::get('/works-websites.html', [SettingsController::class, 'publicWebsitesPage']);
Route::get('/ar/works-websites.html', fn () => app(SettingsController::class)->publicWebsitesPage('ar'));
Route::get('/ku/works-websites.html', fn () => app(SettingsController::class)->publicWebsitesPage('ku'));

Route::get('/works-programs.html', [SettingsController::class, 'publicProgramsPage']);
Route::get('/ar/works-programs.html', fn () => app(SettingsController::class)->publicProgramsPage('ar'));
Route::get('/ku/works-programs.html', fn () => app(SettingsController::class)->publicProgramsPage('ku'));

Route::get('/index.html', [SettingsController::class, 'publicHomePage']);
Route::get('/ar/index.html', fn () => app(SettingsController::class)->publicHomePage('ar'));
Route::get('/ku/index.html', fn () => app(SettingsController::class)->publicHomePage('ku'));

Route::get('/{locale}/{page}.html', function (string $locale, string $page) {
    abort_unless(in_array($locale, ['ar', 'ku'], true), 404);

    $file = base_path("static_site/{$locale}/{$page}.html");
    abort_unless(File::exists($file), 404);

    return response(File::get($file), 200)->header('Content-Type', 'text/html; charset=UTF-8');
})->where('page', '[A-Za-z0-9\-_]+');

Route::get('/{page}.html', function (string $page) {
    $file = base_path("static_site/{$page}.html");
    abort_unless(File::exists($file), 404);

    return response(File::get($file), 200)->header('Content-Type', 'text/html; charset=UTF-8');
})->where('page', '[A-Za-z0-9\-_]+');

Route::prefix('stage-academy-portal')->name('stage-academy-portal.')->group(function () {
    Route::get('/login', [StageAcademyPortalController::class, 'showLogin'])->name('login');
    Route::post('/login', [StageAcademyPortalController::class, 'login'])->name('login.submit');
    Route::get('/dashboard', [StageAcademyPortalController::class, 'dashboard'])->name('dashboard');
    Route::get('/my-courses', [StageAcademyPortalController::class, 'myCourses'])->name('my-courses');
    Route::get('/my-courses/{id}', [StageAcademyPortalController::class, 'myCourseShow'])->name('my-courses.show');
    Route::post('/progress', [StageAcademyPortalController::class, 'updateVideoProgress'])->name('progress');
    Route::get('/categories', [StageAcademyPortalController::class, 'categories'])->name('categories');
    Route::get('/categories/{id}', [StageAcademyPortalController::class, 'category'])->name('categories.show');
    Route::get('/sub-categories/{id}', [StageAcademyPortalController::class, 'subCategory'])->name('sub-categories.show');
    Route::get('/offers', [StageAcademyPortalController::class, 'offers'])->name('offers');
    Route::get('/trainers', [StageAcademyPortalController::class, 'trainers'])->name('trainers');
    Route::get('/trainers/{id}', [StageAcademyPortalController::class, 'trainerShow'])->name('trainers.show');
    Route::get('/profile', [StageAcademyPortalController::class, 'profile'])->name('profile');
    Route::post('/profile', [StageAcademyPortalController::class, 'updateProfile'])->name('profile.update');
});

// Language Switcher (Public)
Route::get('lang/{locale}', [LanguageController::class, 'switchLang'])->name('lang.switch');

Route::get('/login', fn () => redirect('/platform/login'));
Route::post('/login', fn () => redirect('/platform/login', 307));
Route::match(['GET', 'POST'], '/logout', fn () => redirect('/platform/logout', 307));
Route::get('/dashboard', fn () => redirect('/platform/dashboard'));
Route::get('/profile', fn () => redirect('/platform/profile'));

Route::get('/operations/{path?}', fn (string $path = '') => redirect('/platform/operations'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/pos/{path?}', fn (string $path = '') => redirect('/platform/pos'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/products-hub/{path?}', fn (string $path = '') => redirect('/platform/products-hub'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/products/{path?}', fn (string $path = '') => redirect('/platform/products'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/services/{path?}', fn (string $path = '') => redirect('/platform/services'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::middleware('auth')->put('/services/one-time-service/{id}', [OneTimeServiceController::class, 'update']);
Route::get('/customers/{path?}', fn (string $path = '') => redirect('/platform/customers'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/accounts/{path?}', fn (string $path = '') => redirect('/platform/accounts'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::middleware('auth')->put('/employees/{employee}', [EmployeesController::class, 'update'])->whereNumber('employee');
Route::get('/employees/{path?}', fn (string $path = '') => redirect('/platform/employees'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/employees-2', fn () => redirect('/platform/employees-2'));
Route::get('/roles/{path?}', fn (string $path = '') => redirect('/platform/roles'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/system-assistant/{path?}', fn (string $path = '') => redirect('/platform/system-assistant'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/notifications/{path?}', fn (string $path = '') => redirect('/platform/notifications'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/renewals/{path?}', fn (string $path = '') => redirect('/platform/renewals'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/facebook/{path?}', fn (string $path = '') => redirect('/platform/facebook'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/settings/{path?}', fn (string $path = '') => redirect('/platform/settings'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');
Route::get('/tickets', fn () => redirect('/platform/tickets'));
Route::get('/tickets/{id}', fn (int $id) => redirect('/platform/tickets/'.$id))->whereNumber('id');
Route::get('/news', fn () => redirect('/platform/news'));
Route::get('/test-renewals-query', fn () => redirect('/platform/test-renewals-query'));
Route::get('/stage-academy/{path?}', fn (string $path = '') => redirect('/platform/stage-academy'.($path !== '' ? '/'.$path : '')))
    ->where('path', '.*');

Route::prefix('platform')->group(function () {
    Route::get('/', function () {
        return view('welcome');
    });

    // Auth Routes
    Route::get('login', [LoginController::class, 'showLoginForm'])->name('login');
    Route::post('login', [LoginController::class, 'login']);
    Route::match(['GET', 'POST'], 'logout', [LoginController::class, 'logout'])->name('logout');
    Route::get('two-factor/setup', [TwoFactorController::class, 'setup'])->name('two-factor.setup');
    Route::post('two-factor/setup', [TwoFactorController::class, 'setupConfirm'])->name('two-factor.setup.confirm');
    Route::get('two-factor/challenge', [TwoFactorController::class, 'challenge'])->name('two-factor.challenge');
    Route::post('two-factor/challenge', [TwoFactorController::class, 'challengeConfirm'])->name('two-factor.challenge.confirm');

    // Dashboard Routes
    Route::group(['middleware' => ['auth']], function () {
        Route::get('/dashboard', fn () => redirect()->route('system-assistant.notes-reminders'))->name('dashboard');

        // Profile
        Route::get('/profile', [ProfileController::class, 'index'])->name('profile');
        Route::post('/profile', [ProfileController::class, 'updateProfile'])->name('profile.update');
        Route::post('/profile/avatar', [ProfileController::class, 'updateAvatar'])->name('profile.avatar.update');
        Route::post('/profile/password', [ProfileController::class, 'updatePassword'])->name('profile.password.update');
        Route::post('/profile/two-factor/start', [ProfileController::class, 'startTwoFactor'])->name('profile.two-factor.start');
        Route::post('/profile/two-factor/confirm', [ProfileController::class, 'confirmTwoFactor'])->name('profile.two-factor.confirm');
        Route::post('/profile/two-factor/disable', [ProfileController::class, 'disableTwoFactor'])->name('profile.two-factor.disable');

        // Operations Routes
        Route::get('/operations', [OperationsController::class, 'index'])->name('operations'); // Named 'operations' to match sidebar
        Route::get('/operations/list', [OperationsController::class, 'index'])->name('operations.index'); // Alias if needed
        Route::get('/operations/consultations', [OperationsController::class, 'section'])->name('operations.sections.consultations')->defaults('section', 'consultations');
        Route::get('/operations/ads', [OperationsController::class, 'section'])->name('operations.sections.ads')->defaults('section', 'ads');
        Route::get('/operations/custom-app', [OperationsController::class, 'section'])->name('operations.sections.custom_app')->defaults('section', 'custom-app');
        Route::get('/operations/custom-website', [OperationsController::class, 'section'])->name('operations.sections.custom_website')->defaults('section', 'custom-website');
        Route::get('/operations/wordpress', [OperationsController::class, 'section'])->name('operations.sections.wordpress')->defaults('section', 'wordpress');
        Route::get('/operations/domains-emails', [OperationsController::class, 'section'])->name('operations.sections.domains_emails')->defaults('section', 'domains-emails');
        Route::get('/operations/{id}', [OperationsController::class, 'show'])->name('operations.show')->whereNumber('id');
        Route::get('/operations/{serviceId}/kanban/{subscriptionId}', [OperationsController::class, 'showCustomerKanban'])->name('operations.kanban');
        Route::post('/operations/tasks', [OperationsController::class, 'storeTask'])->name('operations.tasks.store');
        Route::post('/operations/tasks/update-status', [OperationsController::class, 'updateTaskStatus'])->name('operations.tasks.update-status');
        Route::post('/operations/tasks/comment', [OperationsController::class, 'addTaskComment'])->name('operations.tasks.comment');
        Route::get('/operations/tasks/{id}', [OperationsController::class, 'getTaskDetails'])->name('operations.tasks.show');
        Route::post('/operations/subscriptions/{subscription}/work-employee', [OperationsController::class, 'updateSubscriptionWorkEmployee'])
            ->middleware('admin')
            ->name('operations.subscriptions.work-employee');
        Route::post('/operations/subscriptions/{subscription}/sales-employee', [OperationsController::class, 'updateSubscriptionSalesEmployee'])
            ->middleware('admin')
            ->name('operations.subscriptions.sales-employee');

        // Campaign Management
        Route::get('/operations/{subscriptionId}/campaigns/manage', [CampaignController::class, 'manage'])->name('operations.campaigns.manage');
        Route::post('/operations/campaigns', [CampaignController::class, 'store'])->name('operations.campaigns.store');
        Route::get('/operations/{subscriptionId}/campaigns/{campaign}/edit', [CampaignController::class, 'edit'])->name('operations.campaigns.edit');
        Route::put('/operations/campaigns/{campaign}', [CampaignController::class, 'update'])->name('operations.campaigns.update');
        Route::post('/operations/campaigns/{campaign}/launch', [CampaignController::class, 'launch'])->name('operations.campaigns.launch');
        Route::post('/operations/campaigns/{campaign}/pause', [CampaignController::class, 'pause'])->name('operations.campaigns.pause');
        Route::post('/operations/campaigns/{campaign}/activate', [CampaignController::class, 'activate'])->name('operations.campaigns.activate');
        Route::post('/operations/campaigns/{campaign}/retry', [CampaignController::class, 'retry'])->name('operations.campaigns.retry');
        Route::post('/operations/campaigns/{campaign}/sync', [CampaignController::class, 'syncInsights'])->name('operations.campaigns.sync');
        Route::get('/operations/campaigns/{campaign}', [CampaignController::class, 'show'])->name('operations.campaigns.show');

        // Ad Sets & Ads Management (Phase 4 & 5)
        Route::post('/operations/campaigns/{campaign}/ad-sets', [AdSetController::class, 'store'])->name('operations.campaigns.ad-sets.store');
        Route::get('/operations/campaigns/{campaign}/ad-sets/{adSet}', [AdSetController::class, 'show'])->name('operations.campaigns.ad-sets.show');
        Route::post('/operations/campaigns/suggest-interests', [AdSetController::class, 'suggestInterests'])->name('operations.campaigns.suggest-interests');

        Route::post('/operations/ad-sets/{adSet}/ads', [AdController::class, 'store'])->name('operations.ad-sets.ads.store');
        Route::post('/operations/ads/suggest-copies', [AdController::class, 'suggestCopies'])->name('operations.ads.suggest-copies');

        // Marketing Intelligence Routes (Phase 5)
        Route::post('/operations/marketing/analyze-performance', [MarketingIntelligenceController::class, 'performanceInsights'])->name('operations.marketing.analyze-performance');
        Route::post('/operations/marketing/suggest-budget', [MarketingIntelligenceController::class, 'optimizeBudget'])->name('operations.marketing.suggest-budget');
        Route::post('/operations/marketing/client-report', [MarketingIntelligenceController::class, 'clientReport'])->name('operations.marketing.client-report');
        Route::post('/operations/marketing/suggest-interests', [MarketingIntelligenceController::class, 'suggestInterests'])->name('operations.marketing.suggest-interests');
        Route::post('/operations/marketing/suggest-ad-copies', [MarketingIntelligenceController::class, 'suggestAdCopies'])->name('operations.marketing.suggest-ad-copies');

        // Renewals Route
        Route::get('/renewals', [RenewalsController::class, 'index'])->name('renewals');
        Route::get('/renewals/software', [RenewalsController::class, 'software'])->name('renewals.software');
        Route::get('/renewals/promotion', [RenewalsController::class, 'promotion'])->name('renewals.promotion');
        Route::get('/renewals/{subscriptionId}/history', [RenewalsController::class, 'history'])->name('renewals.history');

        Route::get('/facebook/integration', [FacebookIntegrationController::class, 'index'])->name('facebook.integration');
        Route::get('/facebook/connect/{integration}', [FacebookIntegrationController::class, 'connect'])->name('facebook.connect');
        Route::get('/facebook/callback', [FacebookIntegrationController::class, 'callback'])->name('facebook.callback');
        Route::post('/facebook/disconnect', [FacebookIntegrationController::class, 'disconnect'])->name('facebook.disconnect');
        Route::get('/facebook/sync/{integration}', [FacebookIntegrationController::class, 'syncCampaigns'])->name('facebook.sync');
        Route::get('/facebook/pages/{integration}', [FacebookIntegrationController::class, 'getPages'])->name('facebook.pages');
        Route::post('/facebook/pages/{integration}', [FacebookIntegrationController::class, 'setPage'])->name('facebook.pages.set');
        Route::get('/facebook/posts/{integration}', [FacebookIntegrationController::class, 'getPosts'])->name('facebook.posts');
        Route::get('/facebook/configure/{integration}', [FacebookIntegrationController::class, 'configure'])->name('facebook.configure');

        // Sub-Service Routes
        Route::get('/services/web-development', [WebDevelopmentController::class, 'index'])->name('services.web_development.index');
        Route::post('/services/web-development', [WebDevelopmentController::class, 'store'])->name('services.web_development.store');
        Route::put('/services/web-development/{id}', [WebDevelopmentController::class, 'update'])->name('services.web_development.update');
        Route::delete('/services/web-development/{id}', [WebDevelopmentController::class, 'destroy'])->name('services.web_development.destroy');
        Route::get('/services/web-development/{id}/invoice', [WebDevelopmentController::class, 'invoice'])->name('services.web_development.invoice');

        Route::get('/services/ads-creation', [AdsCreationController::class, 'index'])->name('services.ads_creation.index');
        Route::post('/services/ads-creation', [AdsCreationController::class, 'store'])->name('services.ads_creation.store');
        Route::put('/services/ads-creation/{id}', [AdsCreationController::class, 'update'])->name('services.ads_creation.update');
        Route::delete('/services/ads-creation/{id}', [AdsCreationController::class, 'destroy'])->name('services.ads_creation.destroy');
        Route::get('/services/ads-creation/{id}/invoice', [AdsCreationController::class, 'invoice'])->name('services.ads_creation.invoice');

        Route::get('/services/one-time-service', [OneTimeServiceController::class, 'index'])->name('services.one_time_service.index');
        Route::post('/services/one-time-service', [OneTimeServiceController::class, 'store'])->name('services.one_time_service.store');
        Route::put('/services/one-time-service/{id}', [OneTimeServiceController::class, 'update'])->name('services.one_time_service.update');
        Route::delete('/services/one-time-service/{id}', [OneTimeServiceController::class, 'destroy'])->name('services.one_time_service.destroy');
        Route::get('/services/one-time-service/{id}/invoice', [OneTimeServiceController::class, 'invoice'])->name('services.one_time_service.invoice');

        // WordPress Templates Routes
        Route::get('/services/wordpress-templates', [WordPressController::class, 'index'])->name('services.wordpress_templates.index');
        Route::post('/services/wordpress-templates', [WordPressController::class, 'store'])->name('services.wordpress_templates.store');
        Route::put('/services/wordpress-templates/{id}', [WordPressController::class, 'update'])->name('services.wordpress_templates.update');
        Route::delete('/services/wordpress-templates/{id}', [WordPressController::class, 'destroy'])->name('services.wordpress_templates.destroy');
        Route::get('/services/wordpress-templates/{id}/invoice', [WordPressController::class, 'invoice'])->name('services.wordpress_templates.invoice');

        Route::get('/services/domains-emails', [DomainsEmailsController::class, 'index'])->name('services.domains_emails.index');
        Route::post('/services/domains-emails', [DomainsEmailsController::class, 'store'])->name('services.domains_emails.store');
        Route::put('/services/domains-emails/{id}', [DomainsEmailsController::class, 'update'])->name('services.domains_emails.update');
        Route::delete('/services/domains-emails/{id}', [DomainsEmailsController::class, 'destroy'])->name('services.domains_emails.destroy');
        Route::get('/services/domains-emails/{id}/invoice', [DomainsEmailsController::class, 'invoice'])->name('services.domains_emails.invoice');

        Route::get('/services/monthly-subscription-limited', [MonthlySubscriptionLimitedController::class, 'index'])->name('services.monthly_subscription_limited.index');
        Route::post('/services/monthly-subscription-limited', [MonthlySubscriptionLimitedController::class, 'store'])->name('services.monthly_subscription_limited.store');
        Route::put('/services/monthly-subscription-limited/{id}', [MonthlySubscriptionLimitedController::class, 'update'])->name('services.monthly_subscription_limited.update');
        Route::delete('/services/monthly-subscription-limited/{id}', [MonthlySubscriptionLimitedController::class, 'destroy'])->name('services.monthly_subscription_limited.destroy');
        Route::get('/services/monthly-subscription-limited/{id}/invoice', [MonthlySubscriptionLimitedController::class, 'invoice'])->name('services.monthly_subscription_limited.invoice');

        Route::get('/services/monthly-subscription-open', [MonthlySubscriptionOpenController::class, 'index'])->name('services.monthly_subscription_open.index');
        Route::post('/services/monthly-subscription-open', [MonthlySubscriptionOpenController::class, 'store'])->name('services.monthly_subscription_open.store');
        Route::put('/services/monthly-subscription-open/{id}', [MonthlySubscriptionOpenController::class, 'update'])->name('services.monthly_subscription_open.update');
        Route::delete('/services/monthly-subscription-open/{id}', [MonthlySubscriptionOpenController::class, 'destroy'])->name('services.monthly_subscription_open.destroy');
        Route::get('/services/monthly-subscription-open/{id}/invoice', [MonthlySubscriptionOpenController::class, 'invoice'])->name('services.monthly_subscription_open.invoice');

        Route::get('/services/app-development', [AppDevelopmentController::class, 'index'])->name('services.app_development.index');
        Route::post('/services/app-development', [AppDevelopmentController::class, 'store'])->name('services.app_development.store');
        Route::put('/services/app-development/{id}', [AppDevelopmentController::class, 'update'])->name('services.app_development.update');
        Route::delete('/services/app-development/{id}', [AppDevelopmentController::class, 'destroy'])->name('services.app_development.destroy');
        Route::get('/services/app-development/{id}/invoice', [AppDevelopmentController::class, 'invoice'])->name('services.app_development.invoice');

        // Services Routes (Defined after specific service routes to avoid conflicts)
        Route::resource('services', ServiceController::class);

        // Chat Routes
        Route::get('/chat', [ChatController::class, 'index'])->name('chat.index');
        Route::get('/chat/messages', [ChatController::class, 'fetchMessages'])->name('chat.messages');
        Route::post('/chat/messages', [ChatController::class, 'sendMessage'])->name('chat.send');
        Route::get('/chat/updates', [ChatController::class, 'pollUpdates'])->name('chat.updates');

        // Admin Chat Routes
        Route::get('/chat/admin/all', [ChatController::class, 'adminAllChats'])->name('chat.admin.all');
        Route::get('/chat/admin/conversation', [ChatController::class, 'adminFetchConversation'])->name('chat.admin.conversation');

        // Customers Routes
        Route::get('/customers', [CustomersController::class, 'index'])->name('customers.index');
        Route::post('/customers', [CustomersController::class, 'store'])->name('customers.store');
        Route::get('/customers/{id}', [CustomersController::class, 'show'])->name('customers.show');
        Route::post('/customers/{id}/subscriptions', [CustomersController::class, 'storeSubscription'])->name('customers.subscriptions.store');
        Route::post('/customers/{id}/renew', [CustomersController::class, 'renew'])->name('customers.renew');
        Route::get('/customers/renewals/{id}/print', [CustomersController::class, 'printRenewal'])->name('customers.renewals.print');
        Route::post('/subscriptions/{subscription}/payments', [CustomersController::class, 'storePayment'])->name('subscriptions.payments.store');
        Route::post('/subscriptions/{subscription}/attachment', [CustomersController::class, 'uploadSubscriptionAttachment'])->name('subscriptions.attachment.store');
        Route::get('/subscriptions/{subscription}/attachments', [CustomersController::class, 'subscriptionAttachmentsIndex'])->name('subscriptions.attachments.index');
        Route::post('/subscriptions/{subscription}/attachments', [CustomersController::class, 'subscriptionAttachmentsStore'])->name('subscriptions.attachments.store');
        Route::delete('/subscriptions/attachments/{attachment}', [CustomersController::class, 'subscriptionAttachmentsDestroy'])->name('subscriptions.attachments.destroy');

        Route::get('/appointments', [SystemAssistantAppointmentsController::class, 'index'])->name('appointments.index');
        Route::post('/appointments', [SystemAssistantAppointmentsController::class, 'store'])->name('appointments.store');
        Route::get('/appointments/{appointment}', [SystemAssistantAppointmentsController::class, 'show'])->name('appointments.show');
        Route::post('/appointments/{appointment}/visits', [SystemAssistantAppointmentsController::class, 'storeVisit'])->name('appointments.visits.store');
        Route::put('/appointments/{appointment}', [SystemAssistantAppointmentsController::class, 'update'])->name('appointments.update');
        Route::delete('/appointments/{appointment}', [SystemAssistantAppointmentsController::class, 'destroy'])->name('appointments.destroy');

        Route::get('/system-assistant/appointments', [SystemAssistantAppointmentsController::class, 'index'])
            ->name('system-assistant.appointments');
        Route::post('/system-assistant/appointments', [SystemAssistantAppointmentsController::class, 'store'])
            ->name('system-assistant.appointments.store');
        Route::get('/system-assistant/appointments/{appointment}', [SystemAssistantAppointmentsController::class, 'show'])
            ->name('system-assistant.appointments.show');
        Route::post('/system-assistant/appointments/{appointment}/visits', [SystemAssistantAppointmentsController::class, 'storeVisit'])
            ->name('system-assistant.appointments.visits.store');
        Route::put('/system-assistant/appointments/{appointment}', [SystemAssistantAppointmentsController::class, 'update'])
            ->name('system-assistant.appointments.update');
        Route::delete('/system-assistant/appointments/{appointment}', [SystemAssistantAppointmentsController::class, 'destroy'])
            ->name('system-assistant.appointments.destroy');
        Route::get('/system-assistant/notes-reminders', [NotesRemindersController::class, 'index'])
            ->name('system-assistant.notes-reminders');

        Route::post('/system-assistant/notes', [NotesRemindersController::class, 'storeNote'])->name('notes-reminders.notes.store');
        Route::put('/system-assistant/notes/{id}', [NotesRemindersController::class, 'updateNote'])->name('notes-reminders.notes.update');
        Route::delete('/system-assistant/notes/{id}', [NotesRemindersController::class, 'destroyNote'])->name('notes-reminders.notes.destroy');
        Route::post('/system-assistant/notes/{id}/pin', [NotesRemindersController::class, 'togglePinNote'])->name('notes-reminders.notes.pin');
        Route::post('/system-assistant/notes/{id}/convert-to-task', [NotesRemindersController::class, 'convertNoteToTask'])->name('notes-reminders.notes.convert-to-task');

        Route::post('/system-assistant/tasks', [NotesRemindersController::class, 'storeTask'])->name('notes-reminders.tasks.store');
        Route::put('/system-assistant/tasks/{id}', [NotesRemindersController::class, 'updateTask'])->name('notes-reminders.tasks.update');
        Route::delete('/system-assistant/tasks/{id}', [NotesRemindersController::class, 'destroyTask'])->name('notes-reminders.tasks.destroy');
        Route::patch('/system-assistant/tasks/{id}/status', [NotesRemindersController::class, 'updateTaskStatus'])->name('notes-reminders.tasks.update-status');

        Route::post('/notifications/{id}/read', [NotificationsController::class, 'markRead'])->name('notifications.read');
        Route::post('/notifications/read-all', [NotificationsController::class, 'markAllRead'])->name('notifications.read-all');
        Route::get('/notifications/poll', [NotificationsController::class, 'poll'])->name('notifications.poll');

        Route::get('/system-assistant', [SystemAssistantController::class, 'index'])->name('system-assistant.index');
        Route::post('/system-assistant/ask', [SystemAssistantController::class, 'ask'])->name('system-assistant.ask');
        Route::post('/system-assistant/message', [SystemAssistantController::class, 'message'])->name('system-assistant.message');

        // POS Routes
        Route::get('/pos', [POSController::class, 'index'])->name('pos');
        Route::get('/pos/services', [POSController::class, 'services'])->name('pos.services');
        Route::get('/pos/products', [POSController::class, 'products'])->name('pos.products');
        Route::get('/pos/stage-academy', [POSController::class, 'stageAcademy'])->name('pos.stage-academy');
        Route::get('/pos/stage-academy/users', [StageAcademyController::class, 'users'])->name('pos.stage-academy.users');
        Route::post('/pos/stage-academy/users', [StageAcademyController::class, 'storeUser'])->name('pos.stage-academy.users.store');
        Route::put('/pos/stage-academy/users/{user}', [StageAcademyController::class, 'updateUser'])->name('pos.stage-academy.users.update');
        Route::delete('/pos/stage-academy/users/{user}', [StageAcademyController::class, 'destroyUser'])->name('pos.stage-academy.users.destroy');
        Route::post('/pos/stage-academy/users/{user}/reset-password', [StageAcademyController::class, 'resetUserPassword'])->name('pos.stage-academy.users.reset-password');
        Route::get('/pos/stage-academy/users/{user}/courses', [StageAcademyController::class, 'userCourses'])->name('pos.stage-academy.users.courses');
        Route::get('/pos/stage-academy/activations', [POSController::class, 'stageAcademyActivations'])->name('pos.stage-academy.activations');
        Route::post('/pos/stage-academy/activations', [POSController::class, 'storeStageAcademyActivation'])->name('pos.stage-academy.activations.store');
        Route::get('/pos/stage-academy/activations/search-users', [POSController::class, 'searchStageAcademyActivationUsers'])->name('pos.stage-academy.activations.search-users');
        Route::get('/pos/stage-academy/activations/search-courses', [POSController::class, 'searchStageAcademyActivationCourses'])->name('pos.stage-academy.activations.search-courses');
        Route::get('/pos/stage-academy/activations/{activation}/invoice', [POSController::class, 'stageAcademyActivationInvoice'])->name('pos.stage-academy.activations.invoice');

        // Products Hub & Related Routes
        Route::get('/products-hub', [ProductsHubController::class, 'index'])->name('products.hub');
        Route::get('/products-hub/{page}', [ProductsHubController::class, 'page'])->name('products.page');

        // Product Items (CRUD)
        Route::get('/products/items', [ProductController::class, 'index'])->name('products.items.index');
        Route::post('/products/items', [ProductController::class, 'store'])->name('products.items.store');
        Route::put('/products/items/{id}', [ProductController::class, 'update'])->name('products.items.update');
        Route::delete('/products/items/{id}', [ProductController::class, 'destroy'])->name('products.items.destroy');

        // Product Colors, Sizes, Measurements, Categories (assuming standard resources or used by PageController views)
        // Adding basics just in case
        Route::resource('product-colors', ProductColorController::class);
        Route::resource('product-sizes', ProductSizeController::class);
        Route::resource('product-measurements', ProductMeasurementController::class);
        Route::resource('main-categories', MainCategoryController::class);
        Route::resource('sub-categories', SubCategoryController::class);
        Route::resource('inventory', InventoryController::class);

        // PageController Routes (matching sidebar)
        Route::get('/accounts', [AccountsController::class, 'index'])->name('accounts');
        Route::get('/accounts/employee-accounts', [AccountsController::class, 'employeeAccounts'])->name('accounts.employee-accounts');
        Route::get('/accounts/employee-accounts/{employee}/print', [AccountsController::class, 'employeeAccountsPrint'])->name('accounts.employee-accounts.print');
        Route::get('/accounts/employee-accounts/{employee}/commissions', [AccountsController::class, 'employeeAccountsCommissions'])->name('accounts.employee-accounts.commissions');
        Route::get('/accounts/monthly-settlement', [AccountsMonthlySettlementController::class, 'index'])->name('accounts.monthly-settlement');
        Route::post('/accounts/monthly-settlement', [AccountsMonthlySettlementController::class, 'store'])->name('accounts.monthly-settlement.store');
        Route::get('/accounts/monthly-settlement/{settlement}', [AccountsMonthlySettlementController::class, 'show'])->name('accounts.monthly-settlement.show');
        Route::get('/accounts/monthly-settlement/{settlement}/print', [AccountsMonthlySettlementController::class, 'print'])->name('accounts.monthly-settlement.print');
        Route::get('/accounts/monthly-settlement/{settlement}/employee/{employee}/print', [AccountsMonthlySettlementController::class, 'employeePrint'])->name('accounts.monthly-settlement.employee.print');
        Route::get('/accounts/expenses', [AccountsExpensesController::class, 'index'])->name('accounts.expenses');
        Route::get('/accounts/expenses/archives', [AccountsExpensesController::class, 'archives'])->name('accounts.expenses.archives');
        Route::get('/accounts/expenses/archives/{archive}', [AccountsExpensesController::class, 'archiveShow'])->name('accounts.expenses.archives.show');
        Route::get('/accounts/expenses/archives/{archive}/print', [AccountsExpensesController::class, 'archivePrint'])->name('accounts.expenses.archives.print');
        Route::post('/accounts/expenses', [AccountsExpensesController::class, 'store'])->name('accounts.expenses.store');
        Route::put('/accounts/expenses/{id}', [AccountsExpensesController::class, 'update'])->name('accounts.expenses.update');
        Route::delete('/accounts/expenses/{id}', [AccountsExpensesController::class, 'destroy'])->name('accounts.expenses.destroy');
        Route::get('/accounts/employee-withdrawals', [AccountsController::class, 'employeeWithdrawals'])->name('accounts.employee-withdrawals');
        Route::post('/accounts/employee-withdrawals', [AccountsController::class, 'employeeWithdrawalsStore'])->name('accounts.employee-withdrawals.store');
        Route::put('/accounts/employee-withdrawals/{id}', [AccountsController::class, 'employeeWithdrawalsUpdate'])->name('accounts.employee-withdrawals.update');
        Route::delete('/accounts/employee-withdrawals/{id}', [AccountsController::class, 'employeeWithdrawalsDestroy'])->name('accounts.employee-withdrawals.destroy');
        Route::get('/accounts/employee-penalties', [AccountsController::class, 'employeePenalties'])->name('accounts.employee-penalties');
        Route::get('/accounts/boxes', [AccountsController::class, 'boxes'])->name('accounts.boxes');
        Route::get('/accounts/penalties', [AccountsController::class, 'penaltiesIndex'])->name('accounts.penalties');
        Route::post('/accounts/penalties', [AccountsController::class, 'penaltiesStore'])->name('accounts.penalties.store');
        Route::put('/accounts/penalties/{id}', [AccountsController::class, 'penaltiesUpdate'])->name('accounts.penalties.update');
        Route::delete('/accounts/penalties/{id}', [AccountsController::class, 'penaltiesDestroy'])->name('accounts.penalties.destroy');
        Route::get('/accounts/employee-bonuses', [AccountsController::class, 'employeeBonuses'])->name('accounts.employee-bonuses');
        Route::post('/accounts/employee-bonuses', [AccountsController::class, 'employeeBonusesStore'])->name('accounts.employee-bonuses.store');
        Route::put('/accounts/employee-bonuses/{id}', [AccountsController::class, 'employeeBonusesUpdate'])->name('accounts.employee-bonuses.update');
        Route::delete('/accounts/employee-bonuses/{id}', [AccountsController::class, 'employeeBonusesDestroy'])->name('accounts.employee-bonuses.destroy');
        Route::get('/accounts/partners', [AccountsController::class, 'partners'])->name('accounts.partners');
        Route::get('/accounts/partners/transfers-to-owner/{transaction}/receipt', [AccountsController::class, 'partnersTransferReceipt'])->name('accounts.partners.transfers-to-owner.receipt');
        Route::get('/accounts/reports', [AccountsController::class, 'reports'])->name('accounts.reports');
        Route::get('/accounts/cash-box', [AccountsController::class, 'cashBox'])->name('accounts.cash-box');
        Route::get('/accounts/online-box', [AccountsController::class, 'onlineBox'])->name('accounts.online-box');
        Route::get('/accounts/reserve-box', [AccountsController::class, 'reserveBox'])->name('accounts.reserve-box');
        Route::post('/accounts/reserve-box/transfer-to-owner', [AccountsController::class, 'reserveBoxTransferToOwner'])->name('accounts.reserve-box.transfer-to-owner');
        Route::post('/accounts/reserve-box/transfer-between-boxes', [AccountsController::class, 'reserveBoxTransferBetweenBoxes'])->name('accounts.reserve-box.transfer-between-boxes');
        Route::post('/accounts/reserve-box/compensation', [AccountsController::class, 'reserveBoxCompensation'])->name('accounts.reserve-box.compensation');
        Route::get('/accounts/reserve-box/compensations/{transaction}/receipt', [AccountsController::class, 'reserveBoxCompensationReceipt'])->name('accounts.reserve-box.compensations.receipt');
        Route::get('/accounts/reserve-box/transfers-to-owner/{transaction}/receipt', [AccountsController::class, 'reserveBoxTransferToOwnerReceipt'])->name('accounts.reserve-box.transfers-to-owner.receipt');
        Route::get('/accounts/debts', [AccountsController::class, 'debts'])->name('accounts.debts');
        Route::get('/accounts/debts/{invoiceId}/payments', [AccountsController::class, 'debtPayments'])->name('accounts.debts.payments');
        Route::get('/accounts/debts/{invoiceId}/invoice', [AccountsController::class, 'debtInvoice'])->name('accounts.debts.invoice');
        Route::post('/accounts/debts/{invoiceId}/payments', [AccountsController::class, 'storeDebtPayment'])->name('accounts.debts.payments.store');
        Route::put('/accounts/debts/payments/{paymentId}', [AccountsController::class, 'updateDebtPayment'])->name('accounts.debts.payments.update');
        Route::delete('/accounts/debts/payments/{paymentId}', [AccountsController::class, 'destroyDebtPayment'])->name('accounts.debts.payments.destroy');
        Route::get('/accounts/transfers', [AccountsController::class, 'transfers'])->name('accounts.transfers');
        Route::post('/accounts/transfers', [AccountsController::class, 'storeTransfer'])->name('accounts.transfers.store');
        Route::put('/accounts/transfers/{id}', [AccountsController::class, 'updateTransfer'])->name('accounts.transfers.update');
        Route::delete('/accounts/transfers/{id}', [AccountsController::class, 'destroyTransfer'])->name('accounts.transfers.destroy');
        Route::get('/accounts/attendance', [AccountsController::class, 'attendance'])->name('accounts.attendance');
        Route::get('/accounts/attendance/today', [AccountsController::class, 'attendanceToday'])->name('accounts.attendance.today');
        Route::get('/accounts/attendance/absences', [AccountsController::class, 'attendanceAbsences'])->name('accounts.attendance.absences');
        Route::get('/accounts/attendance/time-records', [AccountsController::class, 'attendanceTimeRecords'])->name('accounts.attendance.time-records');
        Route::post('/accounts/attendance/time-records/leaves/{leave}/approve', [AccountsController::class, 'approveTimedLeave'])->name('accounts.attendance.time-records.leaves.approve');
        Route::post('/accounts/attendance/time-records/leaves/{leave}/reject', [AccountsController::class, 'rejectTimedLeave'])->name('accounts.attendance.time-records.leaves.reject');
        Route::get('/accounts/attendance/leaves', [AccountsController::class, 'attendanceLeaves'])->name('accounts.attendance.leaves');
        Route::post('/accounts/attendance/leaves/{leave}/approve', [AccountsController::class, 'approveLeave'])->name('accounts.attendance.leaves.approve');
        Route::post('/accounts/attendance/leaves/{leave}/reject', [AccountsController::class, 'rejectLeave'])->name('accounts.attendance.leaves.reject');
        Route::get('/accounts/attendance/reports', [AccountsController::class, 'attendanceReports'])->name('accounts.attendance.reports');
        Route::get('/employees', [EmployeesController::class, 'index'])->name('employees');
        Route::post('/employees', [EmployeesController::class, 'store'])->name('employees.store');
        Route::put('/employees/{employee}', [EmployeesController::class, 'update'])->name('employees.update');
        Route::post('/employees/{employee}/toggle-active', [EmployeesController::class, 'toggleActive'])->name('employees.toggle-active');
        Route::delete('/employees/{employee}', [EmployeesController::class, 'destroy'])->name('employees.destroy');
        Route::get('/roles', [RoleController::class, 'index'])->name('roles.index');
        Route::get('/roles/roles', [RoleController::class, 'rolesIndex'])->name('roles.roles.index');
        Route::get('/roles/roles/create', [RoleController::class, 'create'])->name('roles.roles.create');
        Route::post('/roles/roles', [RoleController::class, 'store'])->name('roles.roles.store');
        Route::get('/roles/roles/{role}/edit', [RoleController::class, 'edit'])->name('roles.roles.edit');
        Route::put('/roles/roles/{role}', [RoleController::class, 'update'])->name('roles.roles.update');
        Route::delete('/roles/roles/{role}', [RoleController::class, 'destroy'])->name('roles.roles.destroy');
        Route::get('/roles/roles/{role}', [RoleController::class, 'show'])->name('roles.roles.show');
        Route::get('/roles/jobs', [RoleController::class, 'jobs'])->name('roles.jobs');
        Route::get('/employees-2', [PageController::class, 'employees2'])->name('employees-2');
        Route::get('/tickets', [TicketController::class, 'index'])->name('tickets');
        Route::post('/tickets', [TicketController::class, 'store'])->name('tickets.store');
        Route::get('/tickets/{id}', [TicketController::class, 'show'])->whereNumber('id')->name('tickets.show');
        Route::post('/tickets/{id}/status', [TicketController::class, 'updateStatus'])->whereNumber('id')->name('tickets.status.update');
        Route::post('/tickets/{id}/assigned-to', [TicketController::class, 'updateAssignedTo'])->whereNumber('id')->name('tickets.assigned_to.update');
        Route::post('/tickets/{id}/messages', [TicketController::class, 'storeMessage'])->whereNumber('id')->name('tickets.messages.store');
        Route::get('/news', [NewsController::class, 'index'])->name('news');
        Route::post('/news', [NewsController::class, 'store'])->name('news.store');
        Route::post('/news/important', [NewsController::class, 'storeImportant'])->name('news.important.store');
        Route::post('/news/alert', [NewsController::class, 'sendAlert'])->name('news.alert.send');
        Route::post('/news/settings', [NewsController::class, 'updateSettings'])->name('news.settings.update');
        Route::post('/news/{id}/toggle', [NewsController::class, 'toggleActive'])->whereNumber('id')->name('news.toggle');
        Route::put('/news/{id}', [NewsController::class, 'update'])->whereNumber('id')->name('news.update');
        Route::delete('/news/{id}', [NewsController::class, 'destroy'])->whereNumber('id')->name('news.destroy');
        Route::get('/settings', [PageController::class, 'settings'])->name('settings');
        Route::get('/settings/company-info', [SettingsController::class, 'companyInfo'])->name('settings.company-info');
        Route::post('/settings/company-info', [SettingsController::class, 'storeCompanyInfo'])->name('settings.company-info.store');
        Route::get('/settings/pos-settings', [SettingsController::class, 'posSettings'])->name('settings.pos-settings');
        Route::post('/settings/pos-settings', [SettingsController::class, 'storePosSettings'])->name('settings.pos-settings.store');
        Route::get('/settings/attendance-settings', [SettingsController::class, 'attendanceSettings'])->name('settings.attendance-settings');
        Route::post('/settings/attendance-settings', [SettingsController::class, 'storeAttendanceSettings'])->name('settings.attendance-settings.store');
        Route::get('/settings/consultations-settings', [SettingsController::class, 'consultationsSettings'])->name('settings.consultations-settings');
        Route::post('/settings/consultations-settings', [SettingsController::class, 'storeConsultationsSettings'])->name('settings.consultations-settings.store');
        Route::get('/settings/deleted-records', [SettingsController::class, 'deletedRecords'])->name('settings.deleted-records');
        Route::post('/settings/deleted-records/{type}/{id}/restore', [SettingsController::class, 'restoreDeletedRecord'])->name('settings.deleted-records.restore');
        Route::delete('/settings/deleted-records/{type}/{id}/force-delete', [SettingsController::class, 'forceDeleteDeletedRecord'])->name('settings.deleted-records.force-delete');
        Route::get('/settings/website/hero', [SettingsController::class, 'websiteHeroSettings'])->name('settings.website.hero');
        Route::post('/settings/website/hero', [SettingsController::class, 'storeWebsiteHeroSettings'])->name('settings.website.hero.store');
        Route::get('/settings/website/apps', [SettingsController::class, 'websiteAppsSettings'])->name('settings.website.apps');
        Route::post('/settings/website/apps', [SettingsController::class, 'storeWebsiteApp'])->name('settings.website.apps.store');
        Route::get('/settings/website/websites', [SettingsController::class, 'websiteWebsitesSettings'])->name('settings.website.websites');
        Route::post('/settings/website/websites', [SettingsController::class, 'storeWebsiteWebsite'])->name('settings.website.websites.store');
        Route::get('/settings/website/programs', [SettingsController::class, 'websiteProgramsSettings'])->name('settings.website.programs');
        Route::post('/settings/website/programs', [SettingsController::class, 'storeWebsiteProgram'])->name('settings.website.programs.store');
        Route::get('/settings/website/{section?}', [SettingsController::class, 'websiteSettings'])->name('settings.website');

        Route::get('/stage-academy', [StageAcademyController::class, 'index'])->name('stage-academy');
        Route::get('/stage-academy/settings', [StageAcademySettingsController::class, 'index'])->name('stage-academy.settings');
        Route::post('/stage-academy/settings/{section}', [StageAcademySettingsController::class, 'store'])->name('stage-academy.settings.store');
        Route::get('/stage-academy/courses', [StageAcademyCoursesController::class, 'index'])->name('stage-academy.courses');
        Route::get('/stage-academy/courses/categories', [StageAcademyCourseCategoriesController::class, 'index'])->name('stage-academy.courses.categories');
        Route::post('/stage-academy/courses/categories', [StageAcademyCourseCategoriesController::class, 'store'])->name('stage-academy.courses.categories.store');
        Route::put('/stage-academy/courses/categories/{id}', [StageAcademyCourseCategoriesController::class, 'update'])->name('stage-academy.courses.categories.update');
        Route::delete('/stage-academy/courses/categories/{id}', [StageAcademyCourseCategoriesController::class, 'destroy'])->name('stage-academy.courses.categories.destroy');
        Route::get('/stage-academy/courses/sub-categories', [StageAcademyCourseSubCategoriesController::class, 'index'])->name('stage-academy.courses.sub_categories');
        Route::post('/stage-academy/courses/sub-categories', [StageAcademyCourseSubCategoriesController::class, 'store'])->name('stage-academy.courses.sub_categories.store');
        Route::put('/stage-academy/courses/sub-categories/{id}', [StageAcademyCourseSubCategoriesController::class, 'update'])->name('stage-academy.courses.sub_categories.update');
        Route::delete('/stage-academy/courses/sub-categories/{id}', [StageAcademyCourseSubCategoriesController::class, 'destroy'])->name('stage-academy.courses.sub_categories.destroy');
        Route::get('/stage-academy/courses/courses-items', [StageAcademyCoursesItemsController::class, 'index'])->name('stage-academy.courses.items');
        Route::post('/stage-academy/courses/courses-items', [StageAcademyCoursesItemsController::class, 'store'])->name('stage-academy.courses.items.store');
        Route::put('/stage-academy/courses/courses-items/{id}', [StageAcademyCoursesItemsController::class, 'update'])->name('stage-academy.courses.items.update');
        Route::delete('/stage-academy/courses/courses-items/{id}', [StageAcademyCoursesItemsController::class, 'destroy'])->name('stage-academy.courses.items.destroy');

        Route::get('/stage-academy/courses/courses-items/{id}/videos', [StageAcademyCoursesItemsController::class, 'videosIndex'])->name('stage-academy.courses.items.videos');
        Route::post('/stage-academy/courses/courses-items/{id}/videos', [StageAcademyCoursesItemsController::class, 'videosStore'])->name('stage-academy.courses.items.videos.store');
        Route::put('/stage-academy/courses/courses-items/{courseId}/videos/{videoId}', [StageAcademyCoursesItemsController::class, 'videosUpdate'])->name('stage-academy.courses.items.videos.update');
        Route::delete('/stage-academy/courses/courses-items/{courseId}/videos/{videoId}', [StageAcademyCoursesItemsController::class, 'videosDestroy'])->name('stage-academy.courses.items.videos.destroy');

        Route::get('/stage-academy/courses/courses-items/{courseId}/questions', [StageAcademyCoursesItemsController::class, 'questionsIndex'])->name('stage-academy.courses.items.questions');
        Route::post('/stage-academy/courses/courses-items/{courseId}/questions', [StageAcademyCoursesItemsController::class, 'questionsStore'])->name('stage-academy.courses.items.questions.store');
        Route::put('/stage-academy/courses/courses-items/{courseId}/questions/{questionId}', [StageAcademyCoursesItemsController::class, 'questionsUpdate'])->name('stage-academy.courses.items.questions.update');
        Route::delete('/stage-academy/courses/courses-items/{courseId}/questions/{questionId}', [StageAcademyCoursesItemsController::class, 'questionsDestroy'])->name('stage-academy.courses.items.questions.destroy');
        Route::get('/stage-academy/users', [StageAcademyController::class, 'users'])->name('stage-academy.users');
        Route::post('/stage-academy/users', [StageAcademyController::class, 'storeUser'])->name('stage-academy.users.store');
        Route::put('/stage-academy/users/{user}', [StageAcademyController::class, 'updateUser'])->name('stage-academy.users.update');
        Route::delete('/stage-academy/users/{user}', [StageAcademyController::class, 'destroyUser'])->name('stage-academy.users.destroy');
        Route::post('/stage-academy/users/{user}/reset-password', [StageAcademyController::class, 'resetUserPassword'])->name('stage-academy.users.reset-password');
        Route::get('/stage-academy/users/{user}/courses', [StageAcademyController::class, 'userCourses'])->name('stage-academy.users.courses');
        Route::get('/stage-academy/activations', [StageAcademyController::class, 'activations'])->name('stage-academy.activations');
        Route::get('/stage-academy/banner', [StageAcademyBannerController::class, 'index'])->name('stage-academy.banner');
        Route::post('/stage-academy/banner', [StageAcademyBannerController::class, 'store'])->name('stage-academy.banner.store');
        Route::put('/stage-academy/banner/{id}', [StageAcademyBannerController::class, 'update'])->name('stage-academy.banner.update');
        Route::delete('/stage-academy/banner/{id}', [StageAcademyBannerController::class, 'destroy'])->name('stage-academy.banner.destroy');
        Route::get('/stage-academy/offers', [StageAcademyOffersController::class, 'index'])->name('stage-academy.offers');
        Route::post('/stage-academy/offers', [StageAcademyOffersController::class, 'store'])->name('stage-academy.offers.store');
        Route::put('/stage-academy/offers/{id}', [StageAcademyOffersController::class, 'update'])->name('stage-academy.offers.update');
        Route::delete('/stage-academy/offers/{id}', [StageAcademyOffersController::class, 'destroy'])->name('stage-academy.offers.destroy');
        Route::get('/stage-academy/institutions', [StageAcademyInstitutionsController::class, 'index'])->name('stage-academy.institutions');
        Route::post('/stage-academy/institutions', [StageAcademyInstitutionsController::class, 'store'])->name('stage-academy.institutions.store');
        Route::put('/stage-academy/institutions/{id}', [StageAcademyInstitutionsController::class, 'update'])->name('stage-academy.institutions.update');
        Route::delete('/stage-academy/institutions/{id}', [StageAcademyInstitutionsController::class, 'destroy'])->name('stage-academy.institutions.destroy');
        Route::get('/stage-academy/trainers', [StageAcademyTrainersController::class, 'index'])->name('stage-academy.trainers');
        Route::post('/stage-academy/trainers', [StageAcademyTrainersController::class, 'store'])->name('stage-academy.trainers.store');
        Route::put('/stage-academy/trainers/{id}', [StageAcademyTrainersController::class, 'update'])->name('stage-academy.trainers.update');
        Route::delete('/stage-academy/trainers/{id}', [StageAcademyTrainersController::class, 'destroy'])->name('stage-academy.trainers.destroy');

        // Test Renewals Query Route (Keeping this for verification)
        Route::get('/test-renewals-query', function () {
            $excludedTypes = ['ads_creation', 'one_time_service'];

            $total = ServiceSubscription::whereNotNull('renewal_due_date')->count();

            $filtered = ServiceSubscription::whereNotNull('renewal_due_date')
                ->whereHas('service', function ($q) use ($excludedTypes) {
                    $q->whereNotIn('type', $excludedTypes);
                })->count();

            $excluded = ServiceSubscription::whereNotNull('renewal_due_date')
                ->whereHas('service', function ($q) use ($excludedTypes) {
                    $q->whereIn('type', $excludedTypes);
                })->count();

            return response()->json([
                'total' => $total,
                'filtered' => $filtered,
                'excluded' => $excluded,
                'check' => ($filtered + $excluded === $total) ? 'PASS' : 'FAIL',
            ]);
        });
    });
});
