<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\BuySMSController;
use App\Http\Controllers\UploadController;
use App\Http\Controllers\ReportsController;
use App\Http\Controllers\WebsiteController;
use App\Http\Controllers\DashboardController;
use App\Http\Controllers\RBAC\RoleController;
use App\Http\Controllers\SMS\File2Controller;
use App\Http\Controllers\PaymentLogController;
use App\Http\Controllers\RBAC\ModuleController;
use App\Http\Controllers\ScheduleSMSController;
use App\Http\Controllers\TransactionController;
use App\Http\Controllers\UserProfileController;
use App\Http\Controllers\DraftMessageController;
use App\Http\Controllers\SMS\CampaignController;
use App\Http\Controllers\SMS\QuickSmsController;
use App\Http\Controllers\ConfigurationController;
use App\Http\Controllers\ticket\TicketController;
use App\Http\Controllers\ticket\CommentController;
use App\Http\Controllers\RBAC\RoleModuleController;
use App\Http\Controllers\SenderIdRequestController;
use App\Http\Controllers\RBAC\RolePermissionController;
use App\Http\Controllers\ticket\NotificationController;
use App\Http\Controllers\ticket\TicketCategoryController;
use App\Http\Controllers\PhoneBook\CampaignListController;
use App\Http\Controllers\UserPackageController;
use App\Http\Controllers\PricingController;
use App\Http\Controllers\PaymentRequestController;

Route::get('/', [WebsiteController::class, 'home'])->name('home');
Route::get('/contact', [WebsiteController::class, 'contact'])->name('web.contact');
Route::get('/register', [WebsiteController::class, 'register'])->name('web.register');
Route::get('/packages', [WebsiteController::class, 'packages'])->name('web.packages');
Route::get('/api_documentation', [WebsiteController::class, 'api_documentation'])->name('web.api_documentation');
Route::post('/message_from_website', [WebsiteController::class, 'message_from_website'])->name('message.from.website');
Route::post('/register_store', [WebsiteController::class, 'registerStore'])->name('registerStore');

Route::middleware('guest')->group(function () {
    Route::get('/login', [AuthController::class, 'loginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'doLogin']);
});

Route::get('/checkResent', [\App\Http\Controllers\TestController::class, 'textResent'])->name('textResent');

Route::get('/home', function () {
    return redirect('/admin/dashboard');
});

Route::get('/run_job', [\App\Http\Controllers\CornJobController::class, 'runJob']);
Route::middleware('auth')->group(function () {
    Route::get('/logout', [AuthController::class, 'logout'])->name('logout');
    Route::view('/admin/{any}', 'backend.index')->where('any', '.*');

    Route::get('/invoice_generate', [TransactionController::class, 'invoiceGenerate']);
    Route::prefix('api')->group(function () {
        Route::post('/configurations', [ConfigurationController::class, 'getConfigurations']);
        Route::post('/file_upload', [UploadController::class, 'uploadFile']);
        Route::post('/image', [UploadController::class, 'imageUpload']);
        Route::post('/excel_upload', [UploadController::class, 'uploadExcelBase']);
        Route::post('/excel_number_delete', [UploadController::class, 'deleteExcelNumber']);
        Route::resource('/edit_user', UserProfileController::class);
        Route::post('/user/theme_mode', [UserProfileController::class, 'updateThemeMode']);
        Route::resource('/users', UserController::class);
        Route::post('/users_api_key_generate', [UserController::class, 'users_api_key_generate']);
        Route::post('/store_generated_api_key', [UserController::class, 'store_generated_api_key']);
        Route::get('/show_api_key', [UserController::class, 'showApiKey']);

        Route::get('/sms_messages', [\App\Http\Controllers\API\SmsMessageController::class, 'index']);
        Route::post('/sms_messages', [\App\Http\Controllers\API\SmsMessageController::class, 'store']);
        Route::patch('/sms_messages/{id}/retry', [\App\Http\Controllers\API\SmsMessageController::class, 'retry']);

        Route::get('/packages_active_list', [PricingController::class, 'getActivePackages']);
        Route::get('/user_active_package', [UserPackageController::class, 'getActivePackage']);
        Route::get('/user_package_history', [UserPackageController::class, 'getHistory']);

        Route::middleware('admin')->group(function () {
            Route::resource('/settings', ConfigurationController::class);
            Route::resource('/user_devices', \App\Http\Controllers\UserDeviceController::class);
            Route::post('/user_devices/status', [\App\Http\Controllers\UserDeviceController::class, 'status']);
            Route::post('/user_devices/bulk_action', [\App\Http\Controllers\UserDeviceController::class, 'bulkAction']);
            Route::post('/user_devices/{id}/force_logout', [\App\Http\Controllers\UserDeviceController::class, 'forceLogout']);
            Route::resource('/operators', \App\Http\Controllers\OperatorController::class);
            Route::resource('/operator_numbers', \App\Http\Controllers\OperatorNumberController::class);
            Route::post('/general', [ConfigurationController::class, 'getGeneralData']);
            Route::resource('/modules', ModuleController::class);
            Route::resource('/roles', RoleController::class);
            Route::resource('/module_permissions', RoleModuleController::class);
            Route::resource('/role_permissions', RolePermissionController::class);

            Route::get('/dashboard', [DashboardController::class, 'dashboardData']);
            Route::resource('/quick_sms', QuickSmsController::class);
            Route::get('/check_api_response', [QuickSmsController::class, 'checkApiResponse']);
            Route::get('/update_check_api_status', [QuickSmsController::class, 'updateCheckApiStatus']);
            Route::get('/manual_check_api', [QuickSmsController::class, 'updateCheckApiStatus2']);
            Route::resource('/schedule_sms', ScheduleSMSController::class);
            Route::resource('/group_sms', \App\Http\Controllers\SMS\GroupController::class);
            Route::resource('/campaign_sms', CampaignController::class);
            Route::resource('/file2_sms', File2Controller::class);
            Route::resource('/sender_id', SenderIdRequestController::class);
            Route::resource('/sender_types', \App\Http\Controllers\SenderTypeController::class);

            Route::post('/default_sender_id/{id}', [SenderIdRequestController::class, 'default_sender_id']);

            Route::resource('/groups', \App\Http\Controllers\PhoneBook\GroupController::class);
            Route::resource('/numbers', \App\Http\Controllers\PhoneBook\NumberController::class);
            Route::post('/numbers/bulk_delete', [\App\Http\Controllers\PhoneBook\NumberController::class, 'bulkDelete']);
            Route::post('/numbers/bulk_import', [\App\Http\Controllers\PhoneBook\NumberController::class, 'bulkImport']);

            Route::delete('/groups/delete_single_number/{id}', [\App\Http\Controllers\PhoneBook\GroupController::class, 'delete_single_number']);
            Route::delete('/delete_single_number/{id}', [CampaignListController::class, 'delete_single_number']);

            Route::resource('/campaigns', CampaignListController::class);
            Route::resource('/draft_message', DraftMessageController::class);

            Route::resource('/payment_log', PaymentLogController::class);
            Route::resource('/transaction', TransactionController::class);
            Route::resource('/payment_request', PaymentRequestController::class);
            Route::post('/payment_request/{id}/approve', [PaymentRequestController::class, 'approve']);
            Route::post('/payment_request/{id}/decline', [PaymentRequestController::class, 'decline']);

            Route::resource('/buy_sms', BuySMSController::class);
            Route::resource('/user_packages', UserPackageController::class);
            Route::post('/user_packages/assign', [UserPackageController::class, 'assign']);

            Route::resource('/failed_logs', \App\Http\Controllers\FailedLogController::class);
            Route::get('/sms_log', [ReportsController::class, 'sms_log']);
            Route::get('/history_log', [ReportsController::class, 'history_log']);
            Route::get('/sms_delivery_report', [ReportsController::class, 'smsDeliveryReport']);

            Route::resource('/ticket_category', TicketCategoryController::class);
            Route::resource('/makings', \App\Http\Controllers\MaskingController::class);
            Route::resource('/ticket', TicketController::class);
            Route::resource('/comment', CommentController::class);
            Route::resource('/notification', NotificationController::class);
            Route::post('/notification/update', [NotificationController::class, 'update']);
            Route::get('/sms_details', [ReportsController::class, 'sms_details']);
            Route::get('/user_wise_recharge', [ReportsController::class, 'user_wise_recharge']);
            Route::get('/coasting_summery', [ReportsController::class, 'coastingSummery']);
            Route::get('/revenue_sharing', [ReportsController::class, 'revenueSharing']);

            Route::get('/contact_from_website', [ReportsController::class, 'contact_from_website']);
            Route::get('/contact_from_website/{id}', [ReportsController::class, 'website_message_view']);

            Route::resource('/pricing', PricingController::class);
        });
    });
});
