<?php

use App\Http\Controllers\Admin\ApiSettingController as AdminApiSettingController;
use App\Http\Controllers\Admin\AdminAvatarController;
use App\Http\Controllers\Admin\AdminMaintenanceController;
use App\Http\Controllers\Admin\AdminPaymentModeController;
use App\Http\Controllers\Admin\AdminPaymentGatewayController;
use App\Http\Controllers\Admin\AdminSubscriptionPlanController;
use App\Http\Controllers\Admin\AppSettingController as AdminAppSettingController;
use App\Http\Controllers\Admin\BadgeController as AdminBadgeController;
use App\Http\Controllers\Admin\ChallengeController as AdminChallengeController;
use App\Http\Controllers\Admin\CommunityController as AdminCommunityController;
use App\Http\Controllers\Admin\CouponController as AdminCouponController;
use App\Http\Controllers\Admin\DashboardController as AdminDashboardController;
use App\Http\Controllers\Admin\DisciplineScoreRuleController as AdminDisciplineScoreRuleController;
use App\Http\Controllers\Admin\EmailBroadcastController as AdminEmailBroadcastController;
use App\Http\Controllers\Admin\EmailSettingController as AdminEmailSettingController;
use App\Http\Controllers\Admin\EmotionTagController as AdminEmotionTagController;
use App\Http\Controllers\Admin\GrowthDashboardController as AdminGrowthDashboardController;
use App\Http\Controllers\Admin\HomepageContentController as AdminHomepageContentController;
use App\Http\Controllers\Admin\LeadMagnetController as AdminLeadMagnetController;
use App\Http\Controllers\Admin\MentorSettingController as AdminMentorSettingController;
use App\Http\Controllers\Admin\MistakeTagController as AdminMistakeTagController;
use App\Http\Controllers\Admin\MotivationController as AdminMotivationController;
use App\Http\Controllers\Admin\PublicProfileSettingController as AdminPublicProfileSettingController;
use App\Http\Controllers\Admin\ReferralController as AdminReferralController;
use App\Http\Controllers\Admin\ReferralSettingController as AdminReferralSettingController;
use App\Http\Controllers\Admin\ShareReportSettingController as AdminShareReportSettingController;
use App\Http\Controllers\Admin\SetupGuideController as AdminSetupGuideController;
use App\Http\Controllers\Admin\SupportSettingController as AdminSupportSettingController;
use App\Http\Controllers\Admin\SupportTicketController as AdminSupportTicketController;
use App\Http\Controllers\Admin\TradingSymbolController as AdminTradingSymbolController;
use App\Http\Controllers\Admin\UserController as AdminUserController;
use App\Http\Controllers\Admin\WaitlistController as AdminWaitlistController;
use App\Http\Controllers\ChallengeController;
use App\Http\Controllers\CommunityController;
use App\Http\Controllers\CurrencyCorrelationController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\ForexCalendarController;
use App\Http\Controllers\InstallerController;
use App\Http\Controllers\MarketNewsController;
use App\Http\Controllers\MarketHoursController;
use App\Http\Controllers\MistakeTrackerController;
use App\Http\Controllers\MentorDashboardController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\PipCalculatorController;
use App\Http\Controllers\PricingController;
use App\Http\Controllers\ProfileController;
use App\Http\Controllers\ProfilePhotoController;
use App\Http\Controllers\PublicStorageController;
use App\Http\Controllers\PublicProfileController;
use App\Http\Controllers\ReferralController;
use App\Http\Controllers\ReportShareController;
use App\Http\Controllers\SubscriptionController;
use App\Http\Controllers\StudentReviewController;
use App\Http\Controllers\SupportController;
use App\Http\Controllers\SupportTeam\SupportTeamDashboardController;
use App\Http\Controllers\SupportTeam\SupportTicketController as SupportTeamTicketController;
use App\Http\Controllers\TradeController;
use App\Http\Controllers\TradingAccountController;
use App\Http\Controllers\TradingToolsController;
use App\Http\Controllers\WaitlistController;
use App\Models\Badge;
use App\Models\HomepageFeature;
use App\Models\HomepageSection;
use App\Models\LeadMagnet;
use App\Models\SiteSetting;
use App\Services\WeeklyTraderRankingService;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Route;

Route::prefix('install')
    ->name('install.')
    ->group(function (): void {
        Route::middleware('redirect_if_installed')->group(function (): void {
            Route::get('/', [InstallerController::class, 'welcome'])->name('welcome');
            Route::get('/requirements', [InstallerController::class, 'requirements'])->name('requirements');
            Route::get('/permissions', [InstallerController::class, 'permissions'])->name('permissions');
            Route::get('/database', [InstallerController::class, 'database'])->name('database');
            Route::post('/database/test', [InstallerController::class, 'testDatabase'])->name('database.test');
            Route::post('/database', [InstallerController::class, 'saveDatabase'])->name('database.save');
            Route::get('/app', [InstallerController::class, 'app'])->name('app');
            Route::post('/app', [InstallerController::class, 'saveApp'])->name('app.save');
            Route::get('/run', [InstallerController::class, 'installing'])->name('installing');
            Route::post('/run', [InstallerController::class, 'run'])->name('run');
        });

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

Route::get('/', function () {
    $homepageSections = collect(HomepageSection::defaults())
        ->map(fn (array $default): HomepageSection => new HomepageSection($default + ['is_active' => true]))
        ->keyBy('key');

    $homepageFeatures = collect(HomepageFeature::defaults())
        ->map(fn (array $default): HomepageFeature => new HomepageFeature($default + ['is_active' => true]));

    $homepageBadges = collect(Badge::defaults())
        ->map(fn (array $default): Badge => new Badge($default + ['is_active' => true]));

    $leadMagnet = new LeadMagnet([
        'title' => 'The 7 Mistakes Forex Traders Repeat Without Knowing',
        'description' => 'Join the early access waitlist and get beginner-friendly education around mistake tracking, discipline, and performance review.',
        'is_active' => true,
    ]);

    $topTraders = [];

    try {
        $homepageSections = HomepageSection::activeByKey();
        $homepageFeatures = HomepageFeature::activeOrdered();
        $homepageBadges = Badge::activeOrdered();
        $leadMagnet = LeadMagnet::active() ?? $leadMagnet;
        $topTraders = app(WeeklyTraderRankingService::class)->currentTopTraders();
    } catch (\Throwable $exception) {
        Log::warning('Homepage dynamic content failed; showing safe defaults.', [
            'message' => $exception->getMessage(),
        ]);
    }

    return view('landing', [
        'homepageSections' => $homepageSections,
        'homepageFeatures' => $homepageFeatures,
        'homepageBadges' => $homepageBadges,
        'leadMagnet' => $leadMagnet,
        'topTraders' => $topTraders,
    ]);
});

Route::get('/maintenance', function () {
    return view('maintenance', [
        'settings' => SiteSetting::maintenanceSettings(),
    ]);
})->name('maintenance');

Route::get('/pricing', PricingController::class)->name('pricing');
Route::get('/storage/{path}', [PublicStorageController::class, 'show'])
    ->where('path', '.*')
    ->name('public-storage.show');
Route::get('/support', [SupportController::class, 'create'])->name('support.create');
Route::post('/support', [SupportController::class, 'store'])->name('support.store');
Route::get('/support/success/{ticket}', [SupportController::class, 'success'])->name('support.success');
Route::post('/waitlist', [WaitlistController::class, 'store'])->name('waitlist.store');
Route::get('/waitlist/success', [WaitlistController::class, 'success'])->name('waitlist.success');
Route::get('/community', [CommunityController::class, 'index'])->name('community.index');
Route::get('/community/posts/{post}', [CommunityController::class, 'show'])->whereNumber('post')->name('community.posts.show');
Route::get('/community/traders/{user}', [CommunityController::class, 'trader'])->name('community.traders.show');

Route::middleware(['auth', 'verified', 'trader'])->group(function () {
    Route::post('/payments/initialize/{plan}', [PaymentController::class, 'initialize'])->name('payments.initialize');
    Route::get('/payments/paystack/callback', [PaymentController::class, 'paystackCallback'])->name('payments.paystack.callback');
    Route::get('/payments/monnify/callback', [PaymentController::class, 'gatewayCallback'])->defaults('gateway', 'monnify')->name('payments.monnify.callback');
    Route::get('/payments/flutterwave/callback', [PaymentController::class, 'gatewayCallback'])->defaults('gateway', 'flutterwave')->name('payments.flutterwave.callback');
    Route::get('/payments/stripe/callback', [PaymentController::class, 'gatewayCallback'])->defaults('gateway', 'stripe')->name('payments.stripe.callback');
    Route::get('/payments/success/{payment}', [PaymentController::class, 'success'])->name('payments.success');
    Route::get('/payments/failed', [PaymentController::class, 'failed'])->name('payments.failed.reference');
    Route::get('/payments/failed/{payment}', [PaymentController::class, 'failed'])->name('payments.failed');

    Route::get('/subscriptions', [SubscriptionController::class, 'index'])->name('subscriptions.index');
    Route::post('/subscriptions/cancel', [SubscriptionController::class, 'cancelPlaceholder'])->name('subscriptions.cancel');
});

Route::post('/payments/{gateway}/webhook', [PaymentController::class, 'webhook'])->name('payments.webhook');

Route::get('/dashboard', DashboardController::class)
    ->middleware(['auth', 'verified', 'trader', 'subscription', 'feature:analytics'])
    ->name('dashboard');

Route::middleware(['auth', 'verified', 'trader', 'subscription'])->group(function () {
    Route::get('/forex-calendar', ForexCalendarController::class)->middleware('feature:forex_calendar')->name('forex-calendar');
    Route::get('/market-news', MarketNewsController::class)->middleware('feature:market_news')->name('market-news');
    Route::get('/trading-tools', TradingToolsController::class)->middleware('feature:trading_tools')->name('trading-tools.index');
    Route::get('/trading-tools/currency-correlation', CurrencyCorrelationController::class)->middleware('feature:trading_tools')->name('trading-tools.currency-correlation');
    Route::get('/trading-tools/market-hours', MarketHoursController::class)->middleware('feature:trading_tools')->name('trading-tools.market-hours');
    Route::get('/trading-tools/pip-calculator', PipCalculatorController::class)->middleware('feature:trading_tools')->name('trading-tools.pip-calculator');

    Route::get('/trades/export/pdf', [TradeController::class, 'exportPdf'])->name('trades.export.pdf');
    Route::get('/trades/calendar', [TradeController::class, 'calendar'])->name('trades.calendar');
    Route::resource('trades', TradeController::class);
});

Route::middleware(['auth', 'verified', 'trader'])->group(function () {
    Route::get('/challenge', [ChallengeController::class, 'index'])->name('challenge.index');
    Route::post('/challenge/{challenge}/join', [ChallengeController::class, 'join'])->name('challenge.join');
    Route::get('/reports/share', [ReportShareController::class, 'index'])->name('reports.share.index');
    Route::get('/reports/share/preview', [ReportShareController::class, 'preview'])->name('reports.share.preview');
    Route::get('/reports/weekly', [ReportShareController::class, 'weekly'])->name('reports.weekly');
    Route::get('/mistake-tracker', [MistakeTrackerController::class, 'index'])->name('mistakes.index');
    Route::get('/community/posts/create', [CommunityController::class, 'create'])->name('community.posts.create');
    Route::post('/community/posts', [CommunityController::class, 'store'])->name('community.posts.store');
    Route::get('/community/posts/{post}/edit', [CommunityController::class, 'edit'])->name('community.posts.edit');
    Route::patch('/community/posts/{post}', [CommunityController::class, 'update'])->name('community.posts.update');
    Route::delete('/community/posts/{post}', [CommunityController::class, 'destroy'])->name('community.posts.destroy');
    Route::delete('/community/posts/{post}/images/{image}', [CommunityController::class, 'destroyImage'])->name('community.posts.images.destroy');
    Route::get('/community/my-posts', [CommunityController::class, 'myPosts'])->name('community.my-posts');
    Route::post('/community/posts/{post}/comments', [CommunityController::class, 'comment'])->name('community.comments.store');
    Route::post('/community/posts/{post}/comments/{comment}/replies', [CommunityController::class, 'reply'])->name('community.comments.reply');
    Route::delete('/community/posts/{post}/comments/{comment}', [CommunityController::class, 'destroyComment'])->name('community.comments.destroy');
    Route::post('/community/posts/{post}/like', [CommunityController::class, 'like'])->name('community.posts.like.ajax');
    Route::delete('/community/posts/{post}/unlike', [CommunityController::class, 'unlike'])->name('community.posts.unlike.ajax');
    Route::post('/community/posts/{post}/likes', [CommunityController::class, 'like'])->name('community.posts.like');
    Route::delete('/community/posts/{post}/likes', [CommunityController::class, 'unlike'])->name('community.posts.unlike');
    Route::post('/community/posts/{post}/reports', [CommunityController::class, 'report'])->name('community.posts.report');
    Route::post('/community/traders/{user}/follow', [CommunityController::class, 'follow'])->name('community.traders.follow');
    Route::delete('/community/traders/{user}/follow', [CommunityController::class, 'unfollow'])->name('community.traders.unfollow');
    Route::get('/community/chat', [CommunityController::class, 'chat'])->name('community.chat');
    Route::post('/community/chat', [CommunityController::class, 'storeMessage'])->name('community.chat.store');
    Route::delete('/community/chat/{message}', [CommunityController::class, 'deleteMessage'])->name('community.chat.destroy');
    Route::get('/student/reviews', [StudentReviewController::class, 'index'])->name('student.reviews.index');
    Route::post('/student/mentor/join', [StudentReviewController::class, 'join'])->name('student.mentor.join');
    Route::post('/trades/{trade}/submit-review', [StudentReviewController::class, 'submit'])->name('trades.submit-review');

    Route::post('/trading-accounts/{trading_account}/connect', [TradingAccountController::class, 'connect'])->name('trading-accounts.connect');
    Route::post('/trading-accounts/{trading_account}/sync', [TradingAccountController::class, 'sync'])->name('trading-accounts.sync');
    Route::post('/trading-accounts/{trading_account}/disconnect', [TradingAccountController::class, 'disconnect'])->name('trading-accounts.disconnect');
    Route::resource('trading-accounts', TradingAccountController::class);

    Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
    Route::get('/referrals', [ReferralController::class, 'index'])->name('referrals.index');
    Route::get('/support/my-tickets', [SupportController::class, 'myTickets'])->name('support.my-tickets');
    Route::get('/support/tickets/{ticket}', [SupportController::class, 'show'])->name('support.tickets.show');
    Route::post('/support/tickets/{ticket}/reply', [SupportController::class, 'reply'])->name('support.tickets.reply');
});

Route::middleware(['auth', 'verified'])->group(function () {
    Route::get('/profile/photo', [ProfilePhotoController::class, 'edit'])->name('profile.photo.edit');
    Route::post('/profile/photo/upload', [ProfilePhotoController::class, 'upload'])->name('profile.photo.upload');
    Route::post('/profile/avatar/select', [ProfilePhotoController::class, 'selectAvatar'])->name('profile.avatar.select');
    Route::delete('/profile/photo/remove', [ProfilePhotoController::class, 'remove'])->name('profile.photo.remove');
});

Route::middleware(['auth', 'verified', 'support_team'])
    ->prefix('support-team')
    ->name('support-team.')
    ->group(function () {
        Route::get('/dashboard', SupportTeamDashboardController::class)->name('dashboard');
        Route::get('/tickets', [SupportTeamTicketController::class, 'index'])->name('tickets.index');
        Route::get('/tickets/{ticket}', [SupportTeamTicketController::class, 'show'])->name('tickets.show');
        Route::post('/tickets/{ticket}/reply', [SupportTeamTicketController::class, 'reply'])->name('tickets.reply');
        Route::patch('/tickets/{ticket}/status', [SupportTeamTicketController::class, 'updateStatus'])->name('tickets.status');
        Route::patch('/tickets/{ticket}/close', [SupportTeamTicketController::class, 'close'])->name('tickets.close');
    });

Route::middleware(['auth', 'verified', 'mentor'])
    ->prefix('mentor')
    ->name('mentor.')
    ->group(function () {
        Route::get('/dashboard', [MentorDashboardController::class, 'index'])->name('dashboard');
        Route::post('/students/invite', [MentorDashboardController::class, 'invite'])->name('students.invite');
        Route::get('/students/{student}', [MentorDashboardController::class, 'student'])->name('students.show');
        Route::get('/students/{student}/trades/{trade}', [MentorDashboardController::class, 'trade'])->name('students.trades.show');
        Route::post('/students/{student}/trades/{trade}/comments', [MentorDashboardController::class, 'comment'])->name('students.trades.comments.store');
    });

Route::middleware(['auth', 'verified', 'admin'])
    ->prefix('admin')
    ->name('admin.')
    ->group(function () {
        Route::get('/dashboard', AdminDashboardController::class)->name('dashboard');
        Route::patch('/avatars/{avatar}/toggle-status', [AdminAvatarController::class, 'toggleStatus'])->name('avatars.toggle-status');
        Route::patch('/avatars/{avatar}/set-default', [AdminAvatarController::class, 'setDefault'])->name('avatars.set-default');
        Route::delete('/avatars/{avatar}/delete', [AdminAvatarController::class, 'destroy'])->name('avatars.delete');
        Route::resource('avatars', AdminAvatarController::class)->except(['show']);
        Route::patch('/users/{user}/toggle-status', [AdminUserController::class, 'toggleStatus'])->name('users.toggle-status');
        Route::patch('/users/{user}/verify-email', [AdminUserController::class, 'markEmailVerified'])->name('users.verify-email');
        Route::get('/support-team', [AdminUserController::class, 'supportTeam'])->name('support-team.index');
        Route::resource('users', AdminUserController::class)->only(['index', 'show', 'edit', 'update', 'destroy']);
        Route::patch('/api-settings/{api_setting}/toggle-status', [AdminApiSettingController::class, 'toggleStatus'])->name('api-settings.toggle-status');
        Route::post('/api-settings/{api_setting}/test', [AdminApiSettingController::class, 'test'])->name('api-settings.test');
        Route::resource('api-settings', AdminApiSettingController::class);
        Route::patch('/motivations/{motivation}/toggle-status', [AdminMotivationController::class, 'toggleStatus'])->name('motivations.toggle-status');
        Route::patch('/motivations/{motivation}/mark-today', [AdminMotivationController::class, 'markToday'])->name('motivations.mark-today');
        Route::resource('motivations', AdminMotivationController::class);
        Route::patch('/trading-symbols/{trading_symbol}/toggle-status', [AdminTradingSymbolController::class, 'toggleStatus'])->name('trading-symbols.toggle-status');
        Route::resource('trading-symbols', AdminTradingSymbolController::class);
        Route::patch('/subscription-plans/{subscription_plan}/toggle-status', [AdminSubscriptionPlanController::class, 'toggleStatus'])->name('subscription-plans.toggle-status');
        Route::patch('/subscription-plans/{subscription_plan}/mark-recommended', [AdminSubscriptionPlanController::class, 'markRecommended'])->name('subscription-plans.mark-recommended');
        Route::resource('subscription-plans', AdminSubscriptionPlanController::class);
        Route::patch('/coupons/{coupon}/toggle-status', [AdminCouponController::class, 'toggleStatus'])->name('coupons.toggle-status');
        Route::resource('coupons', AdminCouponController::class)->except(['show']);
        Route::get('/growth', AdminGrowthDashboardController::class)->name('growth.index');
        Route::get('/community', [AdminCommunityController::class, 'dashboard'])->name('community.dashboard');
        Route::post('/community/rankings/refresh', [AdminCommunityController::class, 'refreshRankings'])->name('community.rankings.refresh');
        Route::get('/community/settings', [AdminCommunityController::class, 'settings'])->name('community.settings');
        Route::patch('/community/settings', [AdminCommunityController::class, 'updateSettings'])->name('community.settings.update');
        Route::get('/community/posts', [AdminCommunityController::class, 'posts'])->name('community.posts');
        Route::patch('/community/posts/{post}/approve', [AdminCommunityController::class, 'approvePost'])->name('community.posts.approve');
        Route::patch('/community/posts/{post}/toggle-hidden', [AdminCommunityController::class, 'togglePostHidden'])->name('community.posts.toggle-hidden');
        Route::patch('/community/posts/{post}/toggle-featured', [AdminCommunityController::class, 'togglePostFeatured'])->name('community.posts.toggle-featured');
        Route::delete('/community/posts/{post}/images/{image}', [AdminCommunityController::class, 'destroyPostImage'])->name('community.posts.images.destroy');
        Route::delete('/community/posts/{post}', [AdminCommunityController::class, 'destroyPost'])->name('community.posts.destroy');
        Route::get('/community/categories', [AdminCommunityController::class, 'categories'])->name('community.categories');
        Route::post('/community/categories', [AdminCommunityController::class, 'storeCategory'])->name('community.categories.store');
        Route::patch('/community/categories/{category}', [AdminCommunityController::class, 'updateCategory'])->name('community.categories.update');
        Route::delete('/community/categories/{category}', [AdminCommunityController::class, 'destroyCategory'])->name('community.categories.destroy');
        Route::get('/community/reports', [AdminCommunityController::class, 'reports'])->name('community.reports');
        Route::patch('/community/reports/{report}', [AdminCommunityController::class, 'updateReport'])->name('community.reports.update');
        Route::get('/community/messages', [AdminCommunityController::class, 'messages'])->name('community.messages');
        Route::patch('/community/messages/{message}/toggle-hidden', [AdminCommunityController::class, 'toggleMessageHidden'])->name('community.messages.toggle-hidden');
        Route::delete('/community/messages/{message}', [AdminCommunityController::class, 'destroyMessage'])->name('community.messages.destroy');
        Route::patch('/community/comments/{comment}/toggle-hidden', [AdminCommunityController::class, 'toggleCommentHidden'])->name('community.comments.toggle-hidden');
        Route::delete('/community/comments/{comment}', [AdminCommunityController::class, 'destroyComment'])->name('community.comments.destroy');
        Route::post('/community/users/{user}/ban', [AdminCommunityController::class, 'banUser'])->name('community.users.ban');
        Route::delete('/community/users/{user}/ban', [AdminCommunityController::class, 'unbanUser'])->name('community.users.unban');
        Route::get('/homepage-content', [AdminHomepageContentController::class, 'index'])->name('homepage-content.index');
        Route::patch('/homepage-content/sections', [AdminHomepageContentController::class, 'updateSections'])->name('homepage-content.sections.update');
        Route::post('/homepage-content/features', [AdminHomepageContentController::class, 'storeFeature'])->name('homepage-content.features.store');
        Route::patch('/homepage-content/features/{homepageFeature}', [AdminHomepageContentController::class, 'updateFeature'])->name('homepage-content.features.update');
        Route::delete('/homepage-content/features/{homepageFeature}', [AdminHomepageContentController::class, 'destroyFeature'])->name('homepage-content.features.destroy');
        Route::resource('challenges', AdminChallengeController::class);
        Route::resource('badges', AdminBadgeController::class)->only(['index', 'store', 'update', 'destroy']);
        Route::resource('mistake-tags', AdminMistakeTagController::class)->only(['index', 'store', 'update', 'destroy']);
        Route::resource('emotion-tags', AdminEmotionTagController::class)->only(['index', 'store', 'update', 'destroy']);
        Route::resource('discipline-score-rules', AdminDisciplineScoreRuleController::class)->only(['index', 'store', 'update', 'destroy']);
        Route::get('/mentor-settings', [AdminMentorSettingController::class, 'index'])->name('mentor-settings.index');
        Route::patch('/mentor-settings', [AdminMentorSettingController::class, 'update'])->name('mentor-settings.update');
        Route::patch('/mentor-settings/users/{user}/approve', [AdminMentorSettingController::class, 'approve'])->name('mentor-settings.users.approve');
        Route::patch('/mentor-settings/users/{user}/block', [AdminMentorSettingController::class, 'block'])->name('mentor-settings.users.block');
        Route::get('/public-profile-settings', [AdminPublicProfileSettingController::class, 'index'])->name('public-profile-settings.index');
        Route::patch('/public-profile-settings', [AdminPublicProfileSettingController::class, 'update'])->name('public-profile-settings.update');
        Route::get('/referral-settings', [AdminReferralSettingController::class, 'index'])->name('referral-settings.index');
        Route::patch('/referral-settings', [AdminReferralSettingController::class, 'update'])->name('referral-settings.update');
        Route::resource('lead-magnets', AdminLeadMagnetController::class)->only(['index', 'store', 'update', 'destroy']);
        Route::get('/share-report-settings', [AdminShareReportSettingController::class, 'index'])->name('share-report-settings.index');
        Route::patch('/share-report-settings', [AdminShareReportSettingController::class, 'update'])->name('share-report-settings.update');
        Route::get('/waitlists/export', [AdminWaitlistController::class, 'export'])->name('waitlists.export');
        Route::get('/waitlists', [AdminWaitlistController::class, 'index'])->name('waitlists.index');
        Route::get('/referrals', [AdminReferralController::class, 'index'])->name('referrals.index');
        Route::get('/support', [AdminSupportTicketController::class, 'index'])->name('support.index');
        Route::get('/support/{ticket}', [AdminSupportTicketController::class, 'show'])->name('support.show');
        Route::post('/support/{ticket}/reply', [AdminSupportTicketController::class, 'reply'])->name('support.reply');
        Route::patch('/support/{ticket}/status', [AdminSupportTicketController::class, 'updateStatus'])->name('support.status');
        Route::patch('/support/{ticket}/close', [AdminSupportTicketController::class, 'close'])->name('support.close');
        Route::delete('/support/{ticket}', [AdminSupportTicketController::class, 'destroy'])->name('support.destroy');
        Route::patch('/payment-gateways/{payment_gateway}/toggle-status', [AdminPaymentGatewayController::class, 'toggleStatus'])->name('payment-gateways.toggle-status');
        Route::post('/payment-gateways/{payment_gateway}/test', [AdminPaymentGatewayController::class, 'test'])->name('payment-gateways.test');
        Route::resource('payment-gateways', AdminPaymentGatewayController::class)->only(['index', 'show', 'edit', 'update']);
        Route::patch('/payment-mode', [AdminPaymentModeController::class, 'update'])->name('payment-mode.update');
        Route::patch('/payment-mode/enable', [AdminPaymentModeController::class, 'enable'])->name('payment-mode.enable');
        Route::patch('/payment-mode/disable', [AdminPaymentModeController::class, 'disable'])->name('payment-mode.disable');
        Route::get('/maintenance', [AdminMaintenanceController::class, 'index'])->name('maintenance.index');
        Route::patch('/maintenance', [AdminMaintenanceController::class, 'update'])->name('maintenance.update');
        Route::patch('/maintenance/enable', [AdminMaintenanceController::class, 'enable'])->name('maintenance.enable');
        Route::patch('/maintenance/disable', [AdminMaintenanceController::class, 'disable'])->name('maintenance.disable');
        Route::patch('/support-settings', [AdminSupportSettingController::class, 'update'])->name('support-settings.update');
        Route::get('/setup-guide', [AdminSetupGuideController::class, 'index'])->name('setup-guide.index');
        Route::post('/setup-guide/test-email', [AdminSetupGuideController::class, 'sendTestEmail'])->name('setup-guide.test-email');
        Route::get('/email-settings', [AdminEmailSettingController::class, 'index'])->name('email-settings.index');
        Route::patch('/email-settings', [AdminEmailSettingController::class, 'update'])->name('email-settings.update');
        Route::get('/email-broadcasts', [AdminEmailBroadcastController::class, 'index'])->name('email-broadcasts.index');
        Route::get('/email-broadcasts/create', [AdminEmailBroadcastController::class, 'create'])->name('email-broadcasts.create');
        Route::post('/email-broadcasts', [AdminEmailBroadcastController::class, 'store'])->name('email-broadcasts.store');
        Route::get('/email-broadcasts/{emailBroadcast}', [AdminEmailBroadcastController::class, 'show'])->name('email-broadcasts.show');
        Route::post('/email-broadcasts/{emailBroadcast}/send', [AdminEmailBroadcastController::class, 'send'])->name('email-broadcasts.send');
        Route::get('/settings', AdminAppSettingController::class)->name('settings.index');
    });

require __DIR__.'/auth.php';

Route::get('/{publicUsername}', [PublicProfileController::class, 'show'])
    ->where('publicUsername', '^(?!install|admin|support-team|mentor|student|auth|login|register|dashboard|trades|trading-tools|trading-accounts|forex-calendar|market-news|pricing|support|payments|subscriptions|profile|referrals|maintenance|challenge|reports|waitlist|community|up$)[A-Za-z0-9_-]+$')
    ->name('public-profile.show');
