<?php

use Illuminate\Support\Facades\Route;


Route::namespace('Auth')->group(function () {
    Route::controller('LoginController')->group(function () {
        Route::get('/', 'showLoginForm')->name('login');
        Route::post('/', 'login')->name('login');
        Route::get('logout', 'logout')->name('logout');
    });

    // Admin Password Reset
    Route::controller('ForgotPasswordController')->prefix('password')->name('password.')->group(function () {
        Route::get('reset', 'showLinkRequestForm')->name('reset');
        Route::post('reset', 'sendResetCodeEmail');
        Route::get('code-verify', 'codeVerify')->name('code.verify');
        Route::post('verify-code', 'verifyCode')->name('verify.code');
    });

    Route::controller('ResetPasswordController')->group(function () {
        Route::get('password/reset/{token}', 'showResetForm')->name('password.reset.form');
        Route::post('password/reset/change', 'reset')->name('password.change');
    });
});

Route::middleware('admin')->group(function () {
    Route::controller('AdminController')->group(function () {

        Route::get('dashboard', 'dashboard')->name('dashboard');
        Route::get('profile', 'profile')->name('profile');
        Route::post('profile', 'profileUpdate')->name('profile.update');
        Route::get('password', 'password')->name('password');
        Route::post('password', 'passwordUpdate')->name('password.update');

        //Notification
        Route::get('notifications', 'notifications')->name('notifications');
        Route::get('notification/read/{id}', 'notificationRead')->name('notification.read');
        Route::get('notifications/read-all', 'readAll')->name('notifications.readAll');

        // //Report Bugs
        // Route::get('request-report', 'requestReport')->name('request.report');
        // Route::post('request-report', 'reportSubmit');

        Route::get('download-attachments/{file_hash}', 'downloadAttachment')->name('download.attachment');
    });

    // Users Manager
    Route::controller('ManageUsersController')->name('users.')->prefix('users')->group(function () {
        Route::get('/', 'allUsers')->name('all')->middleware('permission:manage_user:all_users,admin');
        Route::get('network-full-active', 'fullActivated')->name('full.active')->middleware('permission:manage_user:network_fully_active,admin');
        Route::get('network-plan-purchased', 'planPurchased')->name('plan.purchased')->middleware('permission:manage_user:plan_purchased,admin');
        Route::get('network-pending', 'networkPending')->name('network.pending')->middleware('permission:manage_user:network_pending,admin');
        Route::get('banned', 'bannedUsers')->name('banned')->middleware('permission:manage_user:banned_users,admin');
        Route::get('working', 'activeUsers')->name('active')->middleware('permission:manage_user:working_users,admin');
        Route::get('email-verified', 'emailVerifiedUsers')->name('email.verified')->middleware('permission:manage_user:email_unverified,admin');
        Route::get('email-unverified', 'emailUnverifiedUsers')->name('email.unverified')->middleware('permission:manage_user:email_unverified,admin');
        Route::get('mobile-unverified', 'mobileUnverifiedUsers')->name('mobile.unverified')->middleware('permission:manage_user:mobile_unverified,admin');
        Route::get('kyc-unverified', 'kycUnverifiedUsers')->name('kyc.unverified')->middleware('permission:manage_user:kyc_unverified,admin');
        Route::get('kyc-pending', 'kycPendingUsers')->name('kyc.pending')->middleware('permission:manage_user:kyc_pending,admin');
        Route::get('kyc-rejected', 'kycRejectedUsers')->name('kyc.rejected')->middleware('permission:manage_user:kyc_rejected,admin');
        Route::get('mobile-verified', 'mobileVerifiedUsers')->name('mobile.verified')->middleware('permission:manage_user:mobile_unverified,admin');
        Route::get('app-downloaded', 'appDownloaded')->name('app-downloaded')->middleware('permission:manage_user:app_download_list,admin');
        Route::get('with-balance', 'usersWithBalance')->name('with.balance')->middleware('permission:manage_user:with_earning,admin');
        Route::get('add-User', 'addUser')->name('add.user')->middleware('permission:manage_user:user_create,admin');
        Route::get('not-purchased', 'notPurchased')->name('not.purchased')->middleware('permission:manage_user:network_pending,admin');
        Route::get('plan-purchased', 'planPurchased')->name('plan.purchased')->middleware('permission:manage_user:plan_purchased,admin');
        Route::get('full-activated', 'fullActivated')->name('full.activated')->middleware('permission:manage_user:network_fully_active,admin');
        Route::get('dummy-person', 'dummyPerson')->name('dummy')->middleware('permission:manage_user:dummy_users,admin');
        Route::get('download-app-user-list', 'downloadAppUserList')->name('download.user.list')->middleware('permission:manage_user:app_download_list,admin');
        Route::get('debt-Free', 'debtFree')->name('debtFree')->middleware('permission:manage_user:debt_free,admin');
        Route::get('debt-Not-Free', 'debtNotFree')->name('debtNotFree')->middleware('permission:manage_user:debt_free,admin');
        Route::post('issue-coupon/{id}', 'confirmIssuedCoupon')->name('issue.coupon')->middleware('permission:coupon:create,admin');

        Route::get('detail/{id}', 'detail')->name('detail')->middleware('permission:manage_user:user_edit,admin');
        Route::get('dummy-user-detail/{id}', 'dummyUserdetail')->name('dummyUserdetail')->middleware('permission:manage_user:user_edit,admin');
        Route::post('dummy-user-detail/{id}', 'updateDummyUserDetail')->name('dummy-update')->middleware('permission:manage_user:dummy_users_edit,admin');
        Route::get('kyc-data/{id}', 'kycDetails')->name('kyc.details')->middleware('permission:manage_user:user_kyc_data_edit,admin');
        Route::post('kyc-approve/{id}', 'kycApprove')->name('kyc.approve')->middleware('permission:manage_user:user_kyc_data_verify,admin');
        Route::post('kyc-reject/{id}', 'kycReject')->name('kyc.reject')->middleware('permission:manage_user:user_kyc_data_verify,admin');
        Route::post('store-add-user', 'storeAddUser')->name('create.user')->middleware('permission:manage_user:user_create,admin');
        Route::get('referedPerson-suggestions', 'userSuggestions')->name('referedPerson.suggestions');
        Route::post('update/{id}', 'update')->name('update')->middleware('permission:manage_user:user_edit,admin');
        Route::post('add-sub-balance/{id}', 'addSubBalance')->name('add.sub.balance')->middleware('permission:manage_user:user_balance_edit,admin');
        Route::get('send-notification/{id}', 'showNotificationSingleForm')->name('notification.single');
        Route::post('send-notification/{id}', 'sendNotificationSingle')->name('notification.single');
        Route::get('login/{id}', 'login')->name('login')->middleware('permission:manage_user:login_as_user,admin');
        Route::post('status/{id}', 'status')->name('status')->middleware('permission:manage_user:user_ban,admin');
        Route::post('kyc-admin-submit/{id}', 'kycSubmit')->name('kyc.admin.submit')->middleware('permission:manage_user:user_kyc_data_edit,admin');
        // Route::post('kyc-update/{id}', 'updateKycData')->name('kyc.update');

        Route::get('send-notification', 'showNotificationAllForm')->name('notification.all');
        Route::post('send-notification', 'sendNotificationAll')->name('notification.all.send');
        Route::get('notification-log/{id}', 'notificationLog')->name('notification.log');

        Route::get('referral/commissions/{id}', 'referralCommission')->name('referral.commission');
        Route::get('level/commissions/{id}', 'levelCommission')->name('level.commission');

        //User Pin
        Route::get('generate/pin/{id}', 'generatePin')->name('generate.pin');
        Route::get('used/pin/{id}', 'usedPin')->name('used.pin');

        Route::get('export-user-excel', 'exportUserExcel')->name('export');
        Route::get('generate-pdf', 'generatePdf')->name('generate.pdf');

        Route::get('download-app-excel', 'exportAppExcel')->name('download.app.excel');
        Route::get('download-app-pdf', 'generateAppPdf')->name('download.app.pdf');

        Route::get('download-excel-debt', 'debtFreeExport')->name('download.excel.debt');
        Route::get('download-pdf-debt', 'debtFreeExportPdf')->name('download.pdf.debt');

        Route::get('download-excel-debt-not-cleared', 'debtNotFreeExport')->name('download.excel.debt.notcleard');
        Route::get('download-pdf-debt-not-cleared', 'debtNotFreeExportPdf')->name('download.pdf.debt.notcleard');


    });

    Route::controller('SpatiePermissionController')->middleware('role:super admin,admin')->name('access.')->group(function () {
        Route::get('permission', 'permissions')->name('permissions.index');
        Route::get('role', 'roles')->name('roles.index');
        Route::get('role/create-edit/{id?}', 'createEditRole')->name('roles.create-edit');
        Route::post('role/update-store/{id?}', 'updateStoreRole')->name('roles.update-store');
        Route::get('permission/view/{id}', 'viewPermission')->name('permissions.view');
        Route::get('employees', 'employees')->name('employees');
        Route::get('employees/create-edit/{id?}', 'createEditEmployee')->name('employees.create-edit');
        Route::post('employees/store-update/{id?}', 'storeUpdateEmployee')->name('employees.store-update');
        Route::get('employees/role/{id}', 'editRoleEmployee')->name('employees.edit-role');
        Route::post('employees/update-role/{id}', 'updateRoleEmployee')->name('employees.update-role');
        Route::post('employees/ban/{id}', 'banEmployee')->name('employees.ban');
    });

    Route::controller('LevelController')->prefix('level')->name('level.')->group(function () {
        Route::get('/', 'index')->name('index')->middleware('permission:level_wise_reward:list,admin');
        Route::get('edit-create/{id?}', 'editCreate')->name('edit')->middleware('permission:level_wise_reward:edit,admin');
        Route::post('update-store/{id?}', 'updateStore')->name('update')->middleware('permission:level_wise_reward:edit,admin');
        Route::post('delete/{id}', 'delete')->name('destroy');
    });

    // Subscriber
    Route::controller('SubscriberController')->middleware('role:super admin,admin')->prefix('subscriber')->name('subscriber.')->group(function () {
        Route::get('/', 'index')->name('index');
        Route::get('send-email', 'sendEmailForm')->name('send.email');
        Route::post('remove/{id}', 'remove')->name('remove');
        Route::post('send-email', 'sendEmail')->name('send.email');
    });


    // Deposit Gateway
    Route::name('gateway.')->middleware('role:super admin,admin')->prefix('gateway')->group(function () {

        // Automatic Gateway
        Route::controller('AutomaticGatewayController')->prefix('automatic')->name('automatic.')->group(function () {
            Route::get('/', 'index')->name('index');
            Route::get('edit/{alias}', 'edit')->name('edit');
            Route::post('update/{code}', 'update')->name('update');
            Route::post('remove/{id}', 'remove')->name('remove');
            Route::post('status/{id}', 'status')->name('status');
        });


        // Manual Methods
        Route::controller('ManualGatewayController')->prefix('manual')->name('manual.')->group(function () {
            Route::get('/', 'index')->name('index');
            Route::get('new', 'create')->name('create');
            Route::post('new', 'store')->name('store');
            Route::get('edit/{alias}', 'edit')->name('edit');
            Route::post('update/{id}', 'update')->name('update');
            Route::post('status/{id}', 'status')->name('status');
        });
    });


    // DEPOSIT SYSTEM
    Route::controller('DepositController')->middleware('role:super admin,admin')->prefix('deposit')->name('deposit.')->group(function () {
        Route::get('/', 'deposit')->name('list');
        Route::get('pending', 'pending')->name('pending');
        Route::get('rejected', 'rejected')->name('rejected');
        Route::get('approved', 'approved')->name('approved');
        Route::get('successful', 'successful')->name('successful');
        Route::get('initiated', 'initiated')->name('initiated');
        Route::get('details/{id}', 'details')->name('details');
        Route::post('reject', 'reject')->name('reject');
        Route::post('approve/{id}', 'approve')->name('approve');
    });


    // WITHDRAW SYSTEM
    Route::name('withdraw.')->middleware('role:super admin,admin')->prefix('withdraw')->group(function () {

        Route::controller('WithdrawalController')->group(function () {
            Route::get('pending', 'pending')->name('pending');
            Route::get('approved', 'approved')->name('approved');
            Route::get('rejected', 'rejected')->name('rejected');
            Route::get('log', 'log')->name('log');
            Route::get('details/{id}', 'details')->name('details');
            Route::post('approve', 'approve')->name('approve');
            Route::post('reject', 'reject')->name('reject');
        });


        // Withdraw Method
        Route::controller('WithdrawMethodController')->middleware('role:super admin,admin')->prefix('method')->name('method.')->group(function () {
            Route::get('/', 'methods')->name('index');
            Route::get('create', 'create')->name('create');
            Route::post('create', 'store')->name('store');
            Route::get('edit/{id}', 'edit')->name('edit');
            Route::post('edit/{id}', 'update')->name('update');
            Route::post('status/{id}', 'status')->name('status');
        });
    });

    // Report
    Route::controller('ReportController')->prefix('report')->name('report.')->group(function () {
        Route::get('transaction', 'transaction')->name('transaction')->middleware('permission:report:transactions,admin');
        Route::get('login/history', 'loginHistory')->name('login.history')->middleware('permission:report:login_history,admin');
        Route::get('login/ipHistory/{ip}', 'loginIpHistory')->name('login.ipHistory')->middleware('permission:report:login_history,admin');
        Route::get('notification/history', 'notificationHistory')->name('notification.history')->middleware('permission:report:notification_history,admin');
        Route::get('email/detail/{id}', 'emailDetails')->name('email.details');
        Route::get('transection-report', 'exportTransactionReport')->name('transaction.report');
        Route::get('transection-report-pdf', 'generatePdf')->name('transaction.pdf');

        //Recharge
        Route::get('report/recharge', 'recharge')->name('recharge');

        //Commissions
        Route::get('report/commissions', 'commissions')->name('commissions');
        Route::get('report/commissions/search', 'commissionsSearch')->name('commissions.search');
        Route::get('report/commissions/log', 'commissionSelect')->name('commissions.log');
    });


    // Admin Support
    Route::controller('SupportTicketController')->prefix('ticket')->name('ticket.')->group(function () {
        Route::get('/', 'tickets')->name('index')->middleware('permission:support_ticket:list-all,admin');
        Route::get('pending', 'pendingTicket')->name('pending')->middleware('permission:support_ticket:list-pending,admin');
        Route::get('closed', 'closedTicket')->name('closed')->middleware('permission:support_ticket:list-closed,admin');
        Route::get('answered', 'answeredTicket')->name('answered')->middleware('permission:support_ticket:list-answered,admin');
        Route::get('view/{id}', 'ticketReply')->name('view')->middleware('permission:support_ticket:view,admin');
        Route::post('reply/{id}', 'replyTicket')->name('reply')->middleware('permission:support_ticket:reply,admin');
        Route::post('close/{id}', 'closeTicket')->name('close')->middleware('permission:support_ticket:close,admin');
        Route::get('download/{ticket}', 'ticketDownload')->name('download');
        Route::post('delete/{id}', 'ticketDelete')->name('delete')->middleware('role:super admin,admin');
    });


    // Language Manager
    Route::controller('LanguageController')->middleware('role:super admin,admin')->prefix('language')->name('language.')->group(function () {
        Route::get('/', 'langManage')->name('manage');
        Route::post('/', 'langStore')->name('manage.store');
        Route::post('delete/{id}', 'langDelete')->name('manage.delete');
        Route::post('update/{id}', 'langUpdate')->name('manage.update');
        Route::get('edit/{id}', 'langEdit')->name('key');
        Route::post('import', 'langImport')->name('import.lang');
        Route::post('store/key/{id}', 'storeLanguageJson')->name('store.key');
        Route::post('delete/key/{id}', 'deleteLanguageJson')->name('delete.key');
        Route::post('update/key/{id}', 'updateLanguageJson')->name('update.key');
    });

    Route::controller('GeneralSettingController')->middleware('role:super admin,admin')->group(function () {
        // General Setting
        Route::get('general-setting', 'index')->name('setting.index');
        Route::post('general-setting', 'update')->name('setting.update');

        //configuration
        Route::get('setting/system-configuration', 'systemConfiguration')->name('setting.system.configuration');
        Route::post('setting/system-configuration', 'systemConfigurationSubmit');

        // Logo-Icon
        Route::get('setting/logo-icon', 'logoIcon')->name('setting.logo.icon');
        Route::post('setting/logo-icon', 'logoIconUpdate')->name('setting.logo.icon');

        //Custom CSS
        Route::get('custom-css', 'customCss')->name('setting.custom.css');
        Route::post('custom-css', 'customCssSubmit');

        //Cookie
        Route::get('cookie', 'cookie')->name('setting.cookie');
        Route::post('cookie', 'cookieSubmit');

        //maintenance_mode
        Route::get('maintenance-mode', 'maintenanceMode')->name('maintenance.mode');
        Route::post('maintenance-mode', 'maintenanceModeSubmit');
    });


    //KYC setting
    Route::controller('KycController')->middleware('role:super admin,admin')->group(function () {
        Route::get('kyc-setting', 'setting')->name('kyc.setting');
        Route::post('kyc-setting', 'settingUpdate');
    });

    //Notification Setting
    Route::name('setting.notification.')->middleware('role:super admin,admin')->controller('NotificationController')->prefix('notification')->group(function () {
        //Template Setting
        Route::get('global', 'global')->name('global');
        Route::post('global/update', 'globalUpdate')->name('global.update');
        Route::get('templates', 'templates')->name('templates');
        Route::get('template/edit/{id}', 'templateEdit')->name('template.edit');
        Route::post('template/update/{id}', 'templateUpdate')->name('template.update');

        //Email Setting
        Route::get('email/setting', 'emailSetting')->name('email');
        Route::post('email/setting', 'emailSettingUpdate');
        Route::post('email/test', 'emailTest')->name('email.test');

        //SMS Setting
        Route::get('sms/setting', 'smsSetting')->name('sms');
        Route::post('sms/setting', 'smsSettingUpdate');
        Route::post('sms/test', 'smsTest')->name('sms.test');
    });

    // Plugin
    Route::controller('ExtensionController')->middleware('role:super admin,admin')->prefix('extensions')->name('extensions.')->group(function () {
        Route::get('/', 'index')->name('index');
        Route::post('update/{id}', 'update')->name('update');
        Route::post('status/{id}', 'status')->name('status');
    });


    //System Information
    Route::controller('SystemController')->middleware('role:super admin,admin')->name('system.')->prefix('system')->group(function () {
        Route::get('info', 'systemInfo')->name('info');
        Route::get('server-info', 'systemServerInfo')->name('server.info');
        Route::get('optimize', 'optimize')->name('optimize');
        Route::get('optimize-clear', 'optimizeClear')->name('optimize.clear');
    });


    // SEO
    Route::get('seo', 'FrontendController@seoEdit')->middleware('role:super admin,admin')->name('seo');

    // Plan Controller
    Route::controller('PlanController')->prefix('plan')->name('plan.')->group(function () {
        Route::get('/', 'index')->name('index');
        Route::get('create', 'create')->name('create');
        Route::post('store', 'store')->name('store');
        Route::get('edit/{id}', 'edit')->name('edit')->middleware('permission:product_details:edit,admin');
        Route::post('update/{id}', 'update')->name('update')->middleware('permission:product_details:edit,admin');
        Route::post('setting', 'matrixSetting')->name('matrix.setting');
        Route::post('status/{id}', 'status')->name('status');
    });

    Route::controller('RewardController')->prefix('reward')->name('reward.')->group(function () {
        Route::get('/', 'index')->name('index')->middleware('permission:reward:view_list,admin');
        Route::post('status/{id}', 'status')->name('status')->middleware('permission:reward:approve_reject,admin');
        Route::get('reward-export', 'exportRewardExcel')->name('reward.export');
        Route::get('reward-pdf', 'generateRewardPdf')->name('reward.pdf');
    });

    //Coupon Controller
    Route::controller('CouponController')->prefix('coupon')->name('coupon.')->group(function () {
        Route::get('/', 'index')->name('index')->middleware('permission:coupon:list,admin');
        Route::get('edit-create/{id?}', 'editCreate')->name('edit')->middleware('permission:coupon:edit|coupon:create,admin');
        Route::post('update-store/{id?}', 'updateStore')->name('update')->middleware('permission:coupon:edit|coupon:create,admin');
        Route::post('delete', 'delete')->name('delete');
        Route::post('bulk-upload', 'bulkUpload')->name('bulk-upload')->middleware('permission:coupon:bulk_upload,admin');
        Route::get('sample-bulk-upload', 'sampleBulkUpload')->name('sample-bulk-upload');
        Route::get('coupon-export', 'couponExport')->name('Export');
        Route::get('coupon-pdf', 'couponPdf')->name('pdf');
    });

    //SocialMediaController
    Route::controller('SocialMediaController')->prefix('media')->name('media.')->group(function () {
        Route::get('/', 'index')->name('index')->middleware('permission:social_media:list,admin');
        Route::get('edit-create/{id?}', 'editCreate')->name('edit')->middleware('permission:social_media:edit|social_media:create,admin');
        Route::post('update-store/{id?}', 'updateStore')->name('update')->middleware('permission:social_media:edit|social_media:create,admin');
    });

    //Notice Board
    Route::controller('NoticeBoardController')->middleware('permission:notice_board,admin')->prefix('noticeBoard')->name('noticeBoard.')->group(function () {
        Route::get('/', 'index')->name('index');
        // Route::get('edit-create/{id?}', 'editCreate')->name('edit');
        Route::post('update-store/{id}', 'updateStore')->name('update');
    });


    // Pin Controller
    Route::controller('PinController')->middleware('role:super admin,admin')->prefix('pin')->name('pin.')->group(function () {
        Route::get('/', 'allPins')->name('index');
        Route::post('store', 'store')->name('store');
        Route::get('used', 'usedPins')->name('used');
        Route::get('unused', 'unusedPins')->name('unused');
        Route::get('generate', 'adminPins')->name('generate');
        Route::get('user/generate', 'userPins')->name('user');
    });


    // Frontend
    Route::name('frontend.')->prefix('frontend')->middleware('role:super admin,admin')->group(function () {

        Route::controller('FrontendController')->group(function () {
            Route::get('templates', 'templates')->name('templates');
            Route::post('templates', 'templatesActive')->name('templates.active');
            Route::get('frontend-sections/{key}', 'frontendSections')->name('sections');
            Route::post('frontend-content/{key}', 'frontendContent')->name('sections.content');
            Route::get('frontend-element/{key}/{id?}', 'frontendElement')->name('sections.element');
            Route::post('remove/{id}', 'remove')->name('remove');
            Route::post('create-banner-image/{key}', 'storeBannerImage')->name('store.banner.image');
            Route::get('delete-banner-image/{id}', 'deleteBannerImage')->name('delete.banner.image');
        });

        // Page Builder
        Route::controller('PageBuilderController')->middleware('role:super admin,admin')->group(function () {
            Route::get('manage-pages', 'managePages')->name('manage.pages');
            Route::post('manage-pages', 'managePagesSave')->name('manage.pages.save');
            Route::post('manage-pages/update', 'managePagesUpdate')->name('manage.pages.update');
            Route::post('manage-pages/delete/{id}', 'managePagesDelete')->name('manage.pages.delete');
            Route::get('manage-section/{id}', 'manageSection')->name('manage.section');
            Route::post('manage-section/{id}', 'manageSectionUpdate')->name('manage.section.update');
        });
    });

    Route::controller('ManageUsersController')->name('noteList.')->prefix('noteList')->group(function () {
        Route::get('/', 'downloadNoteList')->name('downloadPdfList')->middleware('permission:file_list,admin');
        Route::get('edit-create/{id?}', 'editCreate')->name('editCreatelist')->middleware('permission:file_list,admin');;
        Route::post('store-update/{id?}', 'createUpdateaPdfList')->name('createUpdateaPdfList')->middleware('permission:file_list,admin');
        Route::get('delete-pdf-list/{id}', 'deleteNoteList')->name('deleteNoteList')->middleware('permission:file_list,admin');
    });

    Route::controller('ManageUsersController')->name('donation.')->prefix('donation')->group(function () {
        Route::get('donation-list', 'donationList')->name('donationlist')->middleware('permission:donation_list,admin');
        Route::get('export-excel-donation-list', 'exportExcelDonationList')->name('exportExcelDonationList');
        Route::get('export-pdf-donation-list', 'exportPdfDonationList')->name('exportPdfDonationList');
    });
});
