<?php

use App\Http\Controllers\CertificateController;
use App\Http\Controllers\CreateSuperAdmin;
use App\Http\Controllers\EnrollController;
use App\Http\Controllers\LanguageController;
use App\Http\Controllers\MasterController;
use App\Http\Controllers\PaymentController;
use App\Http\Controllers\UserVerificationController;
use App\Http\Controllers\WebAdmin\BannerController;
use App\Http\Controllers\WebAdmin\BlogController;
use App\Http\Controllers\WebAdmin\LoginController;
use App\Http\Controllers\WebAdmin\CategoryController;
use App\Http\Controllers\WebAdmin\ChapterController;
use App\Http\Controllers\WebAdmin\CompanyProfileController;
use App\Http\Controllers\WebAdmin\ContactController;
use App\Http\Controllers\WebAdmin\CouponController;
use App\Http\Controllers\WebAdmin\CourseController;
use App\Http\Controllers\WebAdmin\CustomNotificationController;
use App\Http\Controllers\WebAdmin\DashboardController;
use App\Http\Controllers\WebAdmin\DomainController;
use App\Http\Controllers\WebAdmin\EnrollmentController;
use App\Http\Controllers\WebAdmin\ExamController;
use App\Http\Controllers\WebAdmin\InstructorController;
use App\Http\Controllers\WebAdmin\InvoicesController as WebAdminInvoicesController;
use App\Http\Controllers\WebAdmin\ManageCertificateController;
use App\Http\Controllers\WebAdmin\NewslatterController;
use App\Http\Controllers\WebAdmin\NotificationController;
use App\Http\Controllers\WebAdmin\PageController;
use App\Http\Controllers\WebAdmin\PaymentGatewayController;
use App\Http\Controllers\WebAdmin\PlanController;
use App\Http\Controllers\WebAdmin\ProfileController;
use App\Http\Controllers\WebAdmin\QuizController;
use App\Http\Controllers\WebAdmin\ReportController;
use App\Http\Controllers\WebAdmin\ReviewController;
use App\Http\Controllers\WebAdmin\SettingController;
use App\Http\Controllers\WebAdmin\StorageLinkController;
use App\Http\Controllers\WebAdmin\SubscribersController;
use App\Http\Controllers\WebAdmin\TestimonialController;
use App\Http\Controllers\WebAdmin\TransactionController;
use App\Http\Controllers\WebAdmin\UserController;
use App\Http\Controllers\SaasAdmin\AuthController as SaasAdminAuthController;
use App\Http\Controllers\SaasAdmin\BackupController;
use App\Http\Controllers\SaasAdmin\CompanyController as SaasAdminCompanyController;
use App\Http\Controllers\SaasAdmin\CompanyUserController;
use App\Http\Controllers\SaasAdmin\SubscriptionPlanController;
use App\Http\Controllers\TenantDomainAskController;
use App\Http\Controllers\WebAdmin\UserRoleController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Artisan;
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!
|
*/

// Called by the reverse proxy only (see deploy/Caddyfile) to authorize
// on-demand TLS certificate issuance for a custom domain a company has
// pointed at us. Not part of the tenant-facing app.
Route::get('/internal/tls/ask', [TenantDomainAskController::class, 'ask'])->name('internal.tls.ask');

// The SaaS control panel — root-admin only, entirely separate login from
// every tenant's own admin panel. Only reachable on the platform's root
// domain in practice, since a company's own subdomain/custom domain is
// resolved to that company by ResolveTenant before routing even gets here.
Route::prefix('saas-admin')->name('saas-admin.')->group(function () {
    Route::get('/login', [SaasAdminAuthController::class, 'index'])->name('login');
    Route::post('/login', [SaasAdminAuthController::class, 'authenticate'])->name('authenticate');

    Route::middleware('saas.root')->group(function () {
        Route::post('/logout', [SaasAdminAuthController::class, 'logout'])->name('logout');

        Route::get('/companies', [SaasAdminCompanyController::class, 'index'])->name('companies.index');
        Route::get('/companies/create', [SaasAdminCompanyController::class, 'create'])->name('companies.create');
        Route::post('/companies', [SaasAdminCompanyController::class, 'store'])->name('companies.store');
        Route::get('/companies/{company}', [SaasAdminCompanyController::class, 'show'])->name('companies.show');
        Route::post('/companies/{company}/subscription', [SaasAdminCompanyController::class, 'assignSubscription'])->name('companies.subscription');
        Route::post('/companies/{company}/toggle-status', [SaasAdminCompanyController::class, 'toggleStatus'])->name('companies.toggle-status');
        Route::delete('/companies/{company}', [SaasAdminCompanyController::class, 'destroy'])->name('companies.destroy');

        Route::post('/companies/{company}/users', [CompanyUserController::class, 'store'])->name('companies.users.store');
        Route::put('/companies/{company}/users/{user}/reset-password', [CompanyUserController::class, 'resetPassword'])->name('companies.users.reset-password');
        Route::post('/companies/{company}/users/{user}/toggle-active', [CompanyUserController::class, 'toggleActive'])->name('companies.users.toggle-active');

        Route::get('/subscription-plans', [SubscriptionPlanController::class, 'index'])->name('subscription-plans.index');
        Route::get('/subscription-plans/create', [SubscriptionPlanController::class, 'create'])->name('subscription-plans.create');
        Route::post('/subscription-plans', [SubscriptionPlanController::class, 'store'])->name('subscription-plans.store');
        Route::get('/subscription-plans/{plan}/edit', [SubscriptionPlanController::class, 'edit'])->name('subscription-plans.edit');
        Route::put('/subscription-plans/{plan}', [SubscriptionPlanController::class, 'update'])->name('subscription-plans.update');
        Route::delete('/subscription-plans/{plan}', [SubscriptionPlanController::class, 'destroy'])->name('subscription-plans.destroy');

        Route::get('/backups', [BackupController::class, 'index'])->name('backups.index');
        Route::post('/backups', [BackupController::class, 'store'])->name('backups.store');
        Route::get('/backups/{filename}/download', [BackupController::class, 'download'])->name('backups.download');
        Route::delete('/backups/{filename}', [BackupController::class, 'destroy'])->name('backups.destroy');
        Route::post('/backups/restore', [BackupController::class, 'restore'])->name('backups.restore');
        Route::put('/backups/settings', [BackupController::class, 'updateSettings'])->name('backups.settings');
    });
});

Route::controller(CreateSuperAdmin::class)->middleware('guest')->group(function () {
    Route::get('/create-root', 'index')->name('create.root');
    Route::any('/create-superadmin', 'store')->name('create.superadmin');
});

Route::get('/change-language', function (Request $request) {

    if ($request->language) {
        App::setLocale($request->language);
        session()->put('locale', $request->language);
    }

    return back();
})->name('change.language');



Route::prefix('/admin')->group(function () {
    Route::get('/login', [LoginController::class, 'index'])->name('admin.login');
    Route::get('/register', [LoginController::class, 'instructorRegister'])->name('instructor.register');
    Route::post('/register', [LoginController::class, 'instructorAuthenticate'])->name('instructor.authenticate');
    Route::post('/authenticate', [LoginController::class, 'authenticate'])->name('admin.authenticate');
    Route::get('/logout', [LoginController::class, 'logout'])->name('admin.logout')->middleware(['auth:web']);
    Route::get('/email/verify', [UserVerificationController::class, 'index'])->name('verification.index')->middleware('auth:web');
    Route::get('/{email}/resend/otp', [UserVerificationController::class, 'sendotp'])->name('verification.resend.otp');
    Route::post('/email/{email}/verify', [UserVerificationController::class, 'verify'])->name('verification.verify');
});

Route::middleware(['auth:web', 'verication_guard'])->group(function () {
    Route::prefix('/admin')->group(function () {
        Route::get('/dashboard', [DashboardController::class, 'instructorHome'])->name('instructor.dashboard');
        Route::get('/', [DashboardController::class, 'index'])->name('admin.dashboard')->middleware('permission:home.dashboard');
        Route::get('/root/sup-admin/list', [UserController::class, 'admin'])->name('admin.index');
        Route::get('/root/assistant-admin/list', [UserController::class, 'subAdmin'])->name('admin.assistant.index');

        // profile section
        Route::get('/profile', [ProfileController::class, 'index'])->name('admin.profile')->middleware('permission:admin.profile');
        Route::put('/profile/image/update/{user}', [ProfileController::class, 'profileImageUpdate'])->name('admin.profile.image.update')->middleware('permission:admin.profile.image.update');

        // report section
        Route::controller(ReportController::class)->prefix('/report')->group(function () {
            Route::get('/list', 'index')->name('report.index')->middleware('permission:report.index');
            Route::get('/filter', 'filter')->name('report.filter')->middleware('permission:report.filter');
            Route::get('/generate/pdf', 'generatepdf')->name('report.generate.pdf')->middleware('permission:report.generate.pdf');
            Route::get('/exportCSV', 'exportCSV')->name('report.exportCSV')->middleware('permission:report.exportCSV');
        });

        // contact section
        Route::controller(ContactController::class)->prefix('/contact')->group(function () {
            Route::get('/list', 'index')->name('contact.index')->middleware('permission:contact.index');
            Route::get('/show/{contact}', 'show')->name('contact.show')->middleware('permission:contact.index');
            Route::get('/delete/{contact}', 'delete')->name('contact.destroy')->middleware('permission:contact.destroy');
        });

        Route::controller(CategoryController::class)->prefix('category')->group(function () {
            Route::get('/list', 'index')->name('category.index')->middleware('permission:category.index');
            Route::get('/create', 'create')->name('category.create')->middleware('permission:category.create');
            Route::post('/store', 'store')->name('category.store')->middleware('permission:category.store');
            Route::post('/sort', 'sort')->name('category.sort');
            Route::get('/edit/{category}', 'edit')->name('category.edit')->middleware('permission:category.edit');
            Route::put('/update/{category}', 'update')->name('category.update')->middleware(['permission:category.update', 'access_guard']);
            Route::get('/delete/{category}', 'delete')->name('category.destroy')->middleware(['permission:category.destroy', 'access_guard']);
            Route::get('/restore/{id}', 'restore')->name('category.restore')->middleware('permission:category.restore');
        });

        Route::controller(CourseController::class)->prefix('course')->group(function () {
            Route::get('/list', 'index')->name('course.index')->middleware('permission:course.index');
            Route::get('/create', 'create')->name('course.create')->middleware('permission:course.create');
            Route::get('/show/{course}', 'show')->name('course.show')->middleware('permission:course.show');
            Route::post('/store', 'store')->name('course.store')->middleware('permission:course.store');
            Route::get('/edit/{course}', 'edit')->name('course.edit')->middleware('permission:course.edit');
            Route::post('/update/{course}', 'update')->name('course.update')->middleware(['permission:course.update', 'access_guard']);
            Route::get('/delete/{course}', 'delete')->name('course.destroy')->middleware(['permission:course.destroy', 'access_guard']);
            Route::get('/restore/list', 'restoreCourse')->name('course.restore.list')->middleware('permission:course.restore_course');
            Route::get('/restore/{id}', 'restore')->name('course.restore')->middleware('permission:course.restore');
            Route::get('/free/{course}', 'freeCourse')->name('course.free')->middleware('permission:course.free');
        });

        Route::controller(ChapterController::class)->prefix('chapter')->group(function () {
            Route::get('/select_course', 'selectCourse')->name('chapter.select_course')->middleware('permission:chapter.select_course');
            Route::get('/list/{course}', 'index')->name('chapter.index')->middleware('permission:chapter.index');
            Route::get('/create/{course}', 'create')->name('chapter.create')->middleware('permission:chapter.create');
            Route::post('/store', 'store')->name('chapter.store')->middleware('permission:chapter.store');
            Route::get('/edit/{chapter}', 'edit')->name('chapter.edit')->middleware('permission:chapter.edit');
            Route::post('/update/{chapter}', 'update')->name('chapter.update')->middleware(['permission:chapter.update', 'access_guard']);
            Route::get('/delete/{chapter}', 'delete')->name('chapter.destroy')->middleware(['permission:chapter.destroy', 'access_guard']);
        });

        Route::controller(ExamController::class)->prefix('exam')->group(function () {
            Route::get('/select_course', 'selectCourse')->name('exam.select_course')->middleware('permission:exam.select_course');
            Route::get('/list/{course}', 'index')->name('exam.index')->middleware('permission:exam.index');
            Route::get('/create/{course}', 'create')->name('exam.create')->middleware('permission:exam.create');
            Route::post('/store', 'store')->name('exam.store')->middleware('permission:exam.store');
            Route::get('/edit/{exam}', 'edit')->name('exam.edit')->middleware('permission:exam.edit');
            Route::put('/update/{exam}', 'update')->name('exam.update')->middleware('permission:exam.update');
            Route::get('/delete/{exam}', 'delete')->name('exam.destroy')->middleware('permission:exam.destroy');
        });

        Route::controller(QuizController::class)->prefix('quiz')->group(function () {
            Route::get('/select_course', 'selectCourse')->name('quiz.select_course')->middleware('permission:quiz.select_course');
            Route::get('/list/{course}', 'index')->name('quiz.index')->middleware('permission:quiz.index');
            Route::get('/create/{course}', 'create')->name('quiz.create')->middleware('permission:quiz.create');
            Route::post('/store', 'store')->name('quiz.store')->middleware('permission:quiz.store');
            Route::get('/edit/{quiz}', 'edit')->name('quiz.edit')->middleware('permission:quiz.edit');
            Route::put('/update/{quiz}', 'update')->name('quiz.update')->middleware('permission:quiz.update');
            Route::get('/delete/{quiz}', 'delete')->name('quiz.destroy')->middleware('permission:quiz.destroy');
        });

        Route::controller(CouponController::class)->prefix('coupon')->group(function () {
            Route::get('/list', 'index')->name('coupon.index')->middleware('permission:coupon.index');
            Route::get('/create', 'create')->name('coupon.create')->middleware('permission:coupon.create');
            Route::post('/store', 'store')->name('coupon.store')->middleware('permission:coupon.store');
            Route::get('/edit/{coupon}', 'edit')->name('coupon.edit')->middleware('permission:coupon.edit');
            Route::put('/update/{coupon}', 'update')->name('coupon.update')->middleware('permission:coupon.update');
            Route::get('/delete/{coupon}', 'delete')->name('coupon.destroy')->middleware('permission:coupon.destroy');
        });

        Route::controller(EnrollmentController::class)->name('enrollment.')->prefix('enrollment')->group(function () {
            Route::get('/list', 'index')->name('index')->middleware('permission:enrollment.index');
            Route::get('/delete/{enrollment}', 'delete')->name('destroy')->middleware('permission:enrollment.destroy');
            Route::get('/suspended/{enrollment}', 'suspended')->name('suspended')->middleware('permission:enrollment.suspended');
            Route::get('/restore/{id}', 'restore')->name('restore')->middleware('permission:enrollment.restore');
            Route::post('/certificate-name-update/{enrollment}', 'nameUpdate')->name('enrollment.update_certificate_name')->middleware('permission:enrollment.update_certificate_name');
            Route::get('/generate/pdf', 'generatepdf')->name('generate.pdf')->middleware('permission:enrollment.generate.pdf');
            Route::get('/exportCSV', 'exportCSV')->name('exportCSV')->middleware('permission:enrollment.exportCSV');
        });

        Route::controller(ReviewController::class)->prefix('review')->group(function () {
            Route::get('/list', 'index')->name('review.index')->middleware('permission:review.index');
            Route::get('/delete/{review}', 'delete')->name('review.destroy')->middleware('permission:review.destroy');
        });

        Route::controller(InstructorController::class)->prefix('instructor')->group(function () {
            Route::get('/list', 'index')->name('instructor.index')->middleware('permission:instructor.index');
            Route::get('/featured', 'featured')->name('instructor.featured')->middleware('permission:instructor.featured');
            Route::get('/promote/{user}', 'promote')->name('instructor.promote')->middleware('permission:instructor.promote');
            Route::post('/migrate/{user}', 'migrate')->name('instructor.migrate')->middleware('permission:instructor.migrate');
            Route::get('/create', 'create')->name('instructor.create')->middleware('permission:instructor.create');
            Route::post('/store', 'store')->name('instructor.store')->middleware('permission:instructor.store');
            Route::get('/edit/{instructor}', 'edit')->name('instructor.edit')->middleware('permission:instructor.edit');
            Route::put('/update/{instructor}', 'update')->name('instructor.update')->middleware(['permission:instructor.update', 'access_guard']);
            Route::get('/delete/{instructor}', 'delete')->name('instructor.destroy')->middleware(['permission:instructor.destroy', 'access_guard']);
            Route::get('/restore/{id}', 'restore')->name('instructor.restore')->middleware('permission:instructor.restore');
        });

        Route::controller(TransactionController::class)->prefix('transaction')->group(function () {
            Route::get('/list', 'index')->name('transaction.index')->middleware('permission:transaction.index');
        });

        Route::controller(UserController::class)->prefix('user')->group(function () {
            Route::get('/list', 'index')->name('user.index')->middleware('permission:user.index');
            Route::get('/create', 'create')->name('user.create')->middleware('permission:user.create');
            Route::post('/store', 'store')->name('user.store')->middleware('permission:user.store');
            Route::get('/edit/{user}', 'edit')->name('user.edit')->middleware('permission:user.edit');
            Route::put('/update/{user}', 'update')->name('user.update')->middleware(['permission:user.update', 'access_guard']);
            Route::get('/delete/{user}', 'delete')->name('user.destroy')->middleware(['permission:user.destroy', 'access_guard']);
            Route::get('/restore/{id}', 'restore')->name('user.restore')->middleware('permission:user.restore');
            Route::put('/reset-password/{user}', 'resetPassword')->name('user.reset_password')->middleware(['permission:user.reset_password', 'access_guard']);
        });

        Route::controller(PageController::class)->prefix('page')->group(function () {
            Route::get('/list', 'index')->name('page.index')->middleware('permission:page.index');
            Route::get('/edit/{page}', 'edit')->name('page.edit')->middleware('permission:page.edit');
            Route::put('/update/{page}', 'update')->name('page.update')->middleware('permission:page.update');
        });

        Route::controller(SettingController::class)->prefix('setting')->group(function () {
            Route::get('/', 'index')->name('setting.index')->middleware('permission:setting.index');
            Route::put('/update', 'update')->name('setting.update')->middleware(['permission:setting.update', 'access_guard']);
        });

        // Per-company branding — name & logo. Replaces the old global
        // Settings screen for anyone with a company (see SettingController).
        Route::controller(CompanyProfileController::class)->prefix('company-profile')->group(function () {
            Route::get('/', 'index')->name('company-profile.index')->middleware('permission:company_profile.index');
            Route::put('/update', 'update')->name('company-profile.update')->middleware('permission:company_profile.update');
        });

        // A company's own custom-domain screen — see Phase 3 of the SaaS plan.
        Route::controller(DomainController::class)->prefix('domain')->group(function () {
            Route::get('/list', 'index')->name('domain.index')->middleware('permission:domain.index');
            Route::post('/store', 'store')->name('domain.store')->middleware('permission:domain.store');
            Route::post('/verify/{domain}', 'verify')->name('domain.verify')->middleware('permission:domain.verify');
            Route::get('/delete/{domain}', 'delete')->name('domain.destroy')->middleware(['permission:domain.destroy', 'access_guard']);
        });

        Route::controller(PaymentGatewayController::class)->prefix('payment_gateway')->group(function () {
            Route::get('/', 'index')->name('payment_gateway.index')->middleware('permission:payment_gateway.index');
            Route::put('/update/{paymentGateway}', 'update')->name('payment_gateway.update')->middleware('permission:payment_gateway.update');
        });

        Route::controller(NotificationController::class)->prefix('notification')->group(function () {
            Route::get('/list', 'index')->name('notification.index')->middleware('permission:notification.index');
            Route::get('/read/{notificationInstance}', 'markAsRead')->name('notification.read');
            Route::get('/read-all', 'markAsReadAll')->name('notification.read.all');
            Route::get('/edit/{notification}', 'edit')->name('notification.edit')->middleware('permission:notification.edit');
            Route::get('/switch/{notification}/status', 'switchStatus')->name('notification.switch.status')->middleware('permission:notification.switch.status');
            Route::put('/update/{notification}', 'update')->name('notification.update')->middleware('permission:notification.update');

            Route::controller(CustomNotificationController::class)->prefix('/custom')->group(function () {
                Route::get('/list', 'index')->name('notification.custom.index')->middleware('permission:notification.custom.index');
                Route::post('/send/message', 'sendMessage')->name('notification.custom.send.message')->middleware(['permission:notification.custom.send.message', 'access_guard']);
            });
        });

        Route::controller(UserRoleController::class)->prefix('permission&role')->group(function () {
            Route::get('/list', 'index')->name('role.index')->middleware('permission:role.index');
            Route::get('/create', 'create')->name('role.create')->middleware('permission:role.create');
            Route::get('/delete/{role}', 'delete')->name('role.delete')->middleware('permission:role.delete');
            Route::get('/get/permission/{role}', 'getPermission')->name('role.get_permission')->middleware('permission:role.get_permission');
            Route::post('/store', 'store')->name('role.store')->middleware('permission:role.store');
            Route::post('/update/{role}', 'update')->name('role.update')->middleware('permission:role.update');
            Route::post('/assign/roletopermission/{role}', 'assignRoleToPermission')->name('role.assign_roletopermission')->middleware('permission:role.assign_roletopermission');
            Route::post('/assign/roletouser/{user}', 'assignRoleToUser')->name('role.assign_roletouser')->middleware('permission:role.assign_roletouser');
            Route::get('/dispatchRole/{user}/{role}', 'removeRoleFromUser')->name('role.dispatchRole')->middleware('permission:role.dispatchRole');
        });

        Route::controller(TestimonialController::class)->prefix('testimonial')->group(function () {
            Route::get('/list', 'index')->name('testimonial.index')->middleware('permission:testimonial.index');
            Route::get('/create', 'create')->name('testimonial.create')->middleware('permission:testimonial.create');
            Route::post('/store', 'store')->name('testimonial.store')->middleware('permission:testimonial.store');
            Route::get('/edit/{testimonial}', 'edit')->name('testimonial.edit')->middleware('permission:testimonial.edit');
            Route::put('/update/{testimonial}', 'update')->name('testimonial.update')->middleware(['permission:testimonial.update', 'access_guard']);
            Route::get('/delete/{testimonial}', 'destroy')->name('testimonial.destroy')->middleware(['permission:testimonial.destroy', 'access_guard']);
            Route::get('/restore/{testimonial}', 'restore')->name('testimonial.restore')->middleware('permission:testimonial.restore');
        });

        Route::controller(ManageCertificateController::class)->prefix('certificate')->group(function () {
            Route::get('/list', 'index')->name('certificate.index')->middleware('permission:certificate.index');
            Route::post('/update', 'update')->name('certificate.update')->middleware(['permission:certificate.update', 'access_guard']);
            Route::get('/delete/{frame}', 'delete')->name('certificate.delete')->middleware('permission:certificate.delete');
        });

        Route::controller(NewslatterController::class)->prefix('newslatter')->name('newslatter.')->group(function () {
            Route::get('/list', 'index')->name('index')->middleware('permission:newslatter.index');
            Route::get('/delete/{id}', 'delete')->name('delete')->middleware('permission:newslatter.delete');
            Route::get('/restore/{id}', 'restore')->name('restore')->middleware('permission:newslatter.restore');
            Route::get('/send/mail/{id}', 'sendMail')->name('send.mail')->middleware('permission:newslatter.send.mail');
        });

        Route::controller(LanguageController::class)->prefix('language')->name('language.')->group(function () {
            Route::get('/list', 'index')->name('index');
            Route::get('/create', 'create')->name('create');
            Route::post('/store', 'store')->name('store');
            Route::get('/edit/{language}', 'edit')->name('edit');
            Route::put('/update/{language}', 'update')->name('update');
            Route::get('/delete/{language}', 'delete')->name('delete');
            Route::post('/export/{language}', 'export')->name('export');
            Route::post('/import/{language}', 'import')->name('import');
            Route::get('/default/{language}/language', 'setDefaultLanguage')->name('default');
        });


        Route::controller(WebAdminInvoicesController::class)->name('invoice.')->prefix('invoices')->group(function () {
            Route::get('/list', 'index')->name('index')->middleware('permission:invoice.index');
            Route::get('/list/restore', 'restoreTrash')->name('trash')->middleware('permission:invoice.trash');
            Route::get('/create', 'create')->name('create')->middleware('permission:invoice.create');
            Route::post('/store', 'store')->name('store')->middleware('permission:invoice.store');
            Route::get('/edit/{invoice}', 'edit')->name('edit')->middleware('permission:invoice.edit');
            Route::post('/update/{invoice}', 'update')->name('update')->middleware('permission:invoice.update');
            Route::get('/delete/{id}', 'delete')->name('delete')->middleware('permission:invoice.delete');
            Route::get('/restore/{id}', 'restore')->name('restore')->middleware('permission:invoice.restore');
        });

        Route::controller(BannerController::class)->name('banner.')->prefix('banners')->group(function () {
            Route::get('/list', 'index')->name('index')->middleware('permission:banner.index');
            Route::post('/store', 'store')->name('store')->middleware('permission:banner.store');
            Route::post('/update/{id}', 'update')->name('update')->middleware('permission:banner.update');
            Route::get('/delete/{id}', 'delete')->name('delete')->middleware('permission:banner.delete');
            Route::post('/banner-publish', 'publish')->name('publish')->middleware('permission:banner.publish');
        });

        Route::controller(PlanController::class)->name('plan.')->prefix('plans')->group(function () {
            Route::get('/list', 'index')->name('index')->middleware('permission:plan.index');
            Route::get('/create', 'create')->name('create')->middleware('permission:plan.create');
            Route::post('/store', 'store')->name('store')->middleware('permission:plan.store');
            Route::get('/edit/{plan}', 'edit')->name('edit')->middleware('permission:plan.edit');
            Route::post('/update/{plan}', 'update')->name('update')->middleware(['permission:plan.update', 'access_guard']);
            Route::get('/delete/{plan}', 'delete')->name('delete')->middleware(['permission:plan.delete', 'access_guard']);
            Route::get('/trashes', 'trash')->name('trash')->middleware('permission:plan.trash');
            Route::get('/restore/{id}', 'restore')->name('restore')->middleware('permission:plan.restore');
            Route::post('/publish', 'publish')->name('publish')->middleware('permission:plan.publish');
        });

        Route::controller(SubscribersController::class)->name('subscriber.')->prefix('subscribers')->group(function () {
            Route::get('/list', 'index')->name('index')->middleware('permission:subscriber.index');
        });

        Route::get('/link/storage', [StorageLinkController::class, 'linkStorage'])->name('link.storage')->middleware('permission:storage.link.storage');
    });
});

Route::get('/payment/{identifier}', [EnrollController::class, 'paymentView'])->name('payment');

// Paypal
Route::get('paypal/payment/success/{identifier}', [PaymentController::class, 'paypalPaymentSuccess'])->name('paypal.payment.success');
Route::get('paypal/payment/cancel', [PaymentController::class, 'paypalPaymentCancel'])->name('paypal.payment.cancel');

// Stripe
Route::get('stripe/payment/success/{identifier}', [PaymentController::class, 'stripePaymentSuccess'])->name('stripe.payment.success');
Route::get('stripe/payment/cancel', [PaymentController::class, 'stripePaymentCancel'])->name('stripe.payment.cancel');

// AamarPay
Route::post('aamarpay/payment/success', [PaymentController::class, 'aamarpayPaymentSuccess'])->name('aamrpay.payment.success');
Route::post('aamarpay/payment/fail', [PaymentController::class, 'aamarpayPaymentFail'])->name('aamrpay.payment.fail');
Route::get('aamarpay/payment/cancel', [PaymentController::class, 'aamarpayPaymentCancel'])->name('aamrpay.payment.cancel');


// razorpay
Route::get('razorpay/payment/success/{identifier}', [PaymentController::class, 'razorPaySuccess'])->name('razorpay.payment.success');
Route::get('razorpay/payment/fail', [PaymentController::class, 'razorpayPaymentFail'])->name('razorpay.payment.fail');

// Paymob
// Route::get('paymob/payment/success/{identifier}', [PaymentController::class, 'paymobPaymentSuccess'])->name('paymob.payment.success');
// Route::get('paymob/payment/fail', [PaymentController::class, 'paymobPaymentFail'])->name('paymob.payment.fail');
// Route::get('paymob/payment/cancel', [PaymentController::class, 'paymobPaymentCancel'])->name('paymob.payment.cancel');

Route::get('/download_app', [MasterController::class, 'checkDeviceAndRedirect'])->name('download_app');

// downloadable certificate url
Route::controller(CertificateController::class)->group(function () {
    Route::get('/download/certificate/{incodeData}', 'downloadCertificate')->name('download.certificate');
    Route::get('/show/certificate/{course}/{user}', 'ShowCertificate')->name('show.certificate');
});

Route::controller(WebAdminInvoicesController::class)->name('invoice.')->prefix('invoice')->group(function () {
    Route::get('/v/{invoice_token}', 'invoiceVerify')->name('verify');
    Route::get('/download/{invoice_token}', 'invoiceDownload')->name('download');
});

Route::get('/cache/clear', function () {
    try {
        Artisan::call('cache:clear');
        Artisan::call('config:clear');
        Artisan::call('route:clear');
        Artisan::call('view:clear');
    } catch (\Exception $e) {
        return back()->withError($e->getMessage());
    }
    return redirect()->back()->withSuccess('Cache cleared successfully.');
})->name('cache.clear');



// this is proxy url
// Route::get('/', fn() => view('comingsoon'))->name('website');

Route::get('/{any}', function () {
    if (request()->is('admin/*')) {
        return abort(404);
    }

    return view('website');
})->where('any', '.*');
