<?php

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TestApiController;
use App\Http\Controllers\Backend\MemberController;
use Mews\Captcha\Facades\Captcha;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache; // Wajib ditambahkan untuk memori Jackpot

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/sync-togel', [GameController::class, 'cronsjobs'])->name('sync.togel');
Route::get('/sync-turnover', [MemberController::class, 'checkto'])->name('checkto');
Route::get('/sync-provider', [TestApiController::class, 'syncProvider'])->name('sync.provider');
Route::get('/sync-games/{provider}', [TestApiController::class, 'syncGameList'])->name('sync.games');
Route::domain(env('BACKEND_DOMAIN'))->group( function () {
    Route::namespace('Backend')->name('admin.')->group(function () {
        Route::namespace('Auth')->group(function () {
            Route::controller('LoginController')->group(function () {
                Route::get('/', 'showLoginForm')->name('login');
                Route::post('doLogin', 'login')->name('doLogin');
                Route::get('logout', 'logout')->name('logout');
            });
        });

        Route::get('app/cronsjob', 'DashboardController@cron')->name('cron');

        Route::middleware(['admin'])->group(function () {
            Route::get('office/dashboard', 'DashboardController@index')->name('dashboard');
            Route::get('app/transaction-reports', 'DashboardController@reports')->name('reports');

            Route::get('profile', 'ProfileController@index')->name('profile');
            Route::post('profile/update', 'ProfileController@update')->name('profile.update');

            Route::get('members', 'MemberController@index')->name('members.list');
            Route::get('members/turn-over', 'MemberController@turn_over')->name('turnover');
            Route::post('members/turnover', 'MemberController@checkto')->name('members.turnover');
            Route::get('members/create', 'MemberController@create')->name('member.create');
            Route::post('members/create/post', 'MemberController@createp')->name('member.createp');
            Route::get('members/{extplayer}/details', 'MemberController@details')->name('members.list.details');
            Route::get('members/{extplayer}/games/{games}', 'MemberController@games')->name('members.list.games');
            Route::get('members/{extplayer}/status/{status}', 'MemberController@status')->name('members.list.status');
            Route::post('members/{id}/update', 'MemberController@update')->name('members.list.update');
            Route::post('members/{extplayer}/bank', 'MemberController@banks')->name('members.list.bank');
            Route::get('members/balance', 'MemberController@balance')->name('members.balance');
            Route::get('members/{id}/bonus_update_v2', 'MemberController@update_statusc')->name('members.update_statusc');
            Route::get('members/{id}/bonus_update', 'MemberController@update_statusb')->name('members.update_statusb');
            Route::post('members/balance/add', 'MemberController@balanceup')->name('members.balance.update');

            Route::get('deposits/pending', 'DepositController@index')->name('deposits.pending');
            Route::get('deposits/transaction', 'DepositController@list')->name('deposits.list');
            Route::get('deposits/bonus-detail/{id}', 'DepositController@bonus_detail')->name('deposits.bonus_detail');
            Route::get('deposits/{id}/approve', 'DepositController@approve')->name('deposits.approve');
            Route::get('deposits/{id}/reject', 'DepositController@reject')->name('deposits.reject');

            Route::get('banks/account', 'BankController@index')->name('bank.list');
            Route::get('banks/{id}/edit', 'BankController@edit')->name('bank.edit');

            Route::post('banks/create', 'BankController@create')->name('bank.create');
            Route::post('banks/{id}/update', 'BankController@update')->name('bank.update');
            Route::get('banks/{id}/delete', 'BankController@delete')->name('bank.delete');

            Route::get('settings/website/seo_settings', 'SettingController@index')->name('settings.seo');
            Route::get('settings/website/logo_icon', 'SettingController@logo')->name('settings.logo');
            Route::get('settings/website/general_settings', 'SettingController@general')->name('settings.general');
            Route::get('settings/website/contact_settings', 'SettingController@contact')->name('settings.contact');
            Route::get('settings/website/contact_settings/{id}/edit', 'SettingController@contact_edit')->name('settings.contact_edit');
            Route::get('settings/website/contact_settings/{id}/delete', 'SettingController@contact_delete')->name('settings.contact_delete');
            Route::get('settings/config-clear', 'SettingController@clear')->name('settings.clear');
            Route::post('settings/website/seo_update', 'SettingController@seo_update')->name('settings.seo_update');
            Route::post('settings/website/update', 'SettingController@general_update')->name('settings.update');
            Route::post('settings/website/logo_update', 'SettingController@logo_update')->name('settings.logo_update');
            Route::post('settings/website/contact_settings/create_contact', 'SettingController@create_contact')->name('settings.create_contact');
            Route::post('settings/website/contact_settings/{id}/update_contact', 'SettingController@update_contact')->name('settings.update_contact');
            Route::post('settings/website/seo_settings/create_meta', 'SettingController@create_meta')->name('settings.create_meta');
            Route::get('settings/website/seo_settings/{id}/delete', 'SettingController@meta_delete')->name('settings.meta_delete');

            //provider
            Route::get('settings/provider', 'ProviderController@provider')->name('website.provider');
            Route::get('settings/provider/{id}/edit', 'ProviderController@provideredit')->name('website.provider.edit');
            Route::post('settings/provider/{id}/update', 'ProviderController@providerupdate')->name('website.provider.update');
            Route::post('settings/provider/create', 'ProviderController@providercreate')->name('website.provider.create');
            Route::get('settings/provider/{id}/delete', 'ProviderController@providerdelete')->name('website.provider.delete');
            
            //Games
            Route::get('settings/games', 'ProviderController@games')->name('website.games');
            Route::post('settings/games/show', 'ProviderController@games')->name('website.games.show');

            Route::get('settings/api/call-manage', 'ProviderController@call')->name('website.call');
            Route::get('settings/api/call/players', 'ProviderController@call_players')->name('website.call-players');
            Route::get('settings/api/call/list', 'ProviderController@call_list')->name('website.call_list');
            Route::get('settings/api/call/apply', 'ProviderController@call_apply')->name('website.call_apply');
            Route::get('settings/api/call/rtp', 'ProviderController@rtp')->name('website.rtp');

            Route::get('settings/promotion', 'PromotionController@index')->name('website.promotion');
            Route::get('settings/promotion/{id}/edit', 'PromotionController@edit')->name('website.promotion.edit');
            //EVENT
            Route::get('settings/event', 'PromotionController@event')->name('website.event');
            Route::get('settings/event/{id}/edit', 'PromotionController@event')->name('website.event.edit');

            Route::get('settings/promotion-deposit', 'PromotionController@deposit')->name('website.deposit');
            Route::get('settings/promotion-deposit/{id}/edit', 'PromotionController@editd')->name('website.deposit.edit');

            Route::post('settings/promotion/{id}/update', 'PromotionController@update')->name('website.promotion.update');
            Route::post('settings/promotion/create', 'PromotionController@create')->name('website.promotion.create');
            Route::get('settings/promotion/{id}/delete', 'PromotionController@delete')->name('website.promotion.delete');

            Route::get('settings/banner', 'PromotionController@banner')->name('website.banner');
            Route::post('settings/banner/create', 'PromotionController@bcreate')->name('website.banner.create');
            Route::get('settings/banner/{id}/delete', 'PromotionController@bdelete')->name('website.banner.delete');

            Route::get('settings/floating', 'PromotionController@float')->name('website.floating');
            Route::get('settings/floating/{id}/edit', 'PromotionController@floatedit')->name('website.floating.edit');
            Route::post('settings/floating/{id}/update', 'PromotionController@floatupdate')->name('website.floating.update');
            Route::post('settings/floating/create', 'PromotionController@floatcreate')->name('website.floating.create');
            Route::post('settings/popup/update', 'PromotionController@popup')->name('website.floating.popup');
            Route::get('settings/floating/{id}/delete', 'PromotionController@floatdelete')->name('website.floating.delete');
            
            //Theme
            Route::get('settings/theme', 'PromotionController@theme')->name('website.theme');
            Route::get('settings/theme/{id}/edit', 'PromotionController@themeedit')->name('website.theme.edit');
            Route::post('settings/theme/{id}/update', 'PromotionController@themeupdate')->name('website.theme.update');
            Route::post('settings/theme/create', 'PromotionController@themecreate')->name('website.theme.create');
            Route::post('settings/theme/update', 'PromotionController@themeactive')->name('website.theme.active');
            Route::get('settings/theme/{id}/delete', 'PromotionController@themedelete')->name('website.theme.delete');

            Route::get('settings/api/setting', 'ProviderController@index')->name('website.api');
            Route::post('settings/api/edit/{id}', 'ProviderController@edit')->name('website.api.update');
            Route::get('settings/api/use/{id}', 'ProviderController@use')->name('website.api.use');

            Route::get('admin/app/list', 'AdminController@index')->name('admin.list');
            Route::get('admin/app/edit/{id}', 'AdminController@edit')->name('admin.list.edit');
            Route::post('admin/app/create', 'AdminController@create')->name('admin.list.create');
            Route::post('admin/app/update/{id}', 'AdminController@update')->name('admin.list.update');
            Route::get('admin/app/delete/{id}', 'AdminController@delete')->name('admin.list.delete');

            Route::get('withdrawal/pending', 'WithdrawController@index')->name('withdrawal.pending');
            Route::get('withdrawal/transaction', 'WithdrawController@list')->name('withdrawal.list');
            Route::get('withdrawal/{id}/approve', 'WithdrawController@approve')->name('withdrawal.approve');
            Route::get('withdrawal/{id}/reject', 'WithdrawController@reject')->name('withdrawal.reject');

            Route::get('WinLoseReport/WinLose', 'GsReportController@index')->name('winlosereport.winlose');
            Route::get('WinLoseReport/ProductAgentWinLose', 'GsReportController@index')->name('winlosereport.product');
            Route::post('WinLoseReport/SearchWinLoseReport_V2', 'GsReportController@winlose')->name('winlosereport.winloses');

            Route::get('WinLoseSettlementReport/WinLose', 'GsReportController@settlement')->name('settle.winlose');
            Route::get('WinLoseSettlementReport/ProductAgentWinLose', 'GsReportController@settlement')->name('settle.product');
            Route::post('WinLoseSettlementReport/SearchWinLoseReport_V2', 'GsReportController@winloses')->name('settle.winloses');

            Route::get('admin/app/notification', 'AdminController@getNotif')->name('getNotif');
            Route::get('admin/app/notifications', 'AdminController@getNotifwd')->name('getNotif2');

            Route::get('lottery/pasaran', 'TaruhanController@index')->name('taruhan.list');
            Route::get('lottery/pasaran/{id}/edit', 'TaruhanController@pasaranedit')->name('taruhan.list.edit');
            Route::get('lottery/pasaran/{id}/delete', 'TaruhanController@pasarandelete')->name('taruhan.list.delete');
            Route::post('lottery/pasaran/{id}/update', 'TaruhanController@pasaranupdate')->name('taruhan.list.update');
            Route::post('lottery/pasaran/create', 'TaruhanController@pasarancreate')->name('taruhan.list.create');
            Route::get('lottery/result', 'TaruhanController@result')->name('taruhan.result');
            Route::post('lottery/result/create', 'TaruhanController@create')->name('taruhan.create');
            Route::get('lottery/betting/active', 'TaruhanController@active')->name('taruhan.active');
            Route::get('lottery/betting/history', 'TaruhanController@history')->name('taruhan.history');
            Route::get('lottery/betting/settings', 'TaruhanController@settings')->name('taruhan.settings');
            Route::post('lottery/betting/settings/update', 'TaruhanController@settingsupdate')->name('taruhan.settings.update');
            Route::post('taruhan/approve', 'TaruhanController@approve')->name('taruhan.approve');
            Route::post('taruhan/reject', 'TaruhanController@reject')->name('taruhan.reject');
            Route::get('rollingan-setting', 'RollinganSettingController@index')->name('rollingan.index');
            Route::post('rollingan-setting', 'RollinganSettingController@store')->name('rollingan.store');
            Route::delete('rollingan-setting/{id}', 'RollinganSettingController@destroy')->name('rollingan.destroy');
            
            Route::post('rollingan-manual-sync', 'RollinganSettingController@manualSync')->name('rollingan.manual_sync');
            Route::post('rollingan-manual-distribute', 'RollinganSettingController@manualDistribute')->name('rollingan.manual_distribute');
            // Report Data Rollingan
            Route::get('rollingan-turnover', 'RollinganSettingController@turnover')->name('rollingan.turnover');
            Route::get('rollingan-history', 'RollinganSettingController@history')->name('rollingan.history');
        });
    });

    Route::get('config-clear', function () {
        Artisan::call('optimize:clear');
        return back()->with('success','Cache clear successfully');
    });
});
Route::namespace('Frontend')->group(function () {
    Route::middleware(['guest'])->group(function () {
    
        Route::post('/func/account/forget', 'UserController@forgotPassword')->name('forgot.password.submit');
        Route::get('/', 'HomeController@index')->name('home.guest'); // Nama disesuaikan agar tidak bentrok
        Route::get('/register', 'HomeController@register')->name('register');
        Route::get('/ref', 'HomeController@ref')->name('referral.link');
        
        Route::get('/download/apk', 'HomeController@download')->name('download.apk');
        
        Route::get('/home', 'HomeController@index');
        Route::get('/daftar', 'HomeController@daftar')->name('daftar');
        Route::get('/promotions', 'HomeController@promotions')->name('promotions');
        
        Route::get('/sportsbook', 'GameController@sportsbook')->name('sportsbook.provider');
        Route::get('/livecasino', 'GameController@livecasino')->name('livecasino.provider');
        Route::get('/poker', 'GameController@poker')->name('poker.provider');
        Route::get('/tangkas', 'GameController@tangkas')->name('tangkas.provider');
        Route::get('/fish', 'GameController@fish')->name('fish.provider');
        Route::get('/others', 'GameController@others')->name('others.provider');
        Route::get('/hot', 'GameController@hot')->name('hot.provider');
        Route::get('/slots-provider', 'GameController@slotsProvider')->name('slots.provider');
        
        Route::get('/slots', 'GameController@index');
        Route::get('/casino', 'GameController@casino');
        Route::get('/sportsbook/games', 'GameController@sportsGames');
        Route::get('/poker/games', 'GameController@pokerGames');
        Route::get('/fish/games', 'GameController@fishGames');
        Route::get('/tangkas/games', 'GameController@tangkasGames');
        Route::get('/hot/games', 'GameController@hotGames');
        Route::get('/others/games', 'GameController@othersGames');
        
        Route::get('/{slug}', 'HomeController@showPage')
            ->where('slug', 'aboutus|tnc|policy|responsible-gaming|faq|contact')
            ->name('info.pages');
    });
    
    Route::get('func/cms/getBannerList', 'HomeController@getBannerList')->name('api.banners');
    Route::get('/func/common/getBank', function () {
        return response()->json(['success' => true, 'data' => []], 200);
    });
    //Route::get('/func/stl/getSlotGameList', 'GameController@getSlotGameList');
    Route::get('/ajax/stl/getSlotGameList', 'GameController@getSlotGameList');
    //Route::get('/func/stl/getLiveCasinoGameList', 'GameController@getLiveCasinoGameList');
    Route::get('/func/stl/getGameListAPI', 'GameController@getGameListAPI');

    Route::group(['prefix' => 'secure', 'middleware' => 'auth'], function () {
        Route::get('/slots', 'GameController@index');
        Route::get('/casino', 'GameController@casino');
        Route::get('/sportsbook/games', 'GameController@sportsGames');
        Route::get('/poker/games', 'GameController@pokerGames');
        Route::get('/fish/games', 'GameController@fishGames');
        Route::get('/tangkas/games', 'GameController@tangkasGames');
        Route::get('/hot/games', 'GameController@hotGames');
        Route::get('/others/games', 'GameController@othersGames');
        
        Route::get('/sportsbook', 'GameController@sportsbook');
        Route::get('/livecasino', 'GameController@livecasino');
        Route::get('/poker', 'GameController@poker');
        Route::get('/tangkas', 'GameController@tangkas');
        Route::get('/fish', 'GameController@fish');
        Route::get('/others', 'GameController@others');
        Route::get('/hot', 'GameController@hot');
        Route::get('/slots-provider', 'GameController@slotsProvider')->name('secure.slots.provider');
        // HOME & DASHBOARD
        Route::get('/home', 'HomeController@index')->name('secure.home');
        Route::get('/promotions', 'HomeController@promotions')->name('secure.promotions');
        Route::get('/{slug}', 'HomeController@showPage')
            ->where('slug', 'aboutus|tnc|policy|responsible-gaming|faq|contact')
            ->name('secure.info');
        
        Route::get('/admin/profile', 'UserController@profile')->name('secure.profile');
        Route::get('/admin/messages', 'UserController@message')->name('secure.message');
        Route::get('/admin/messages/send', 'UserController@readMessage')->name('secure.message.send');
        // REFERRAL
        Route::get('/admin/referral', 'UserController@referral')->name('secure.referral');
        
        // TRANSAKSI & DOMPET
        Route::get('/admin/deposit', 'TransactionController@deposit')->name('secure.deposit');
        Route::get('/admin/withdrawal', 'TransactionController@withdraw')->name('secure.withdrawal');
        
        Route::get('/admin/bonus', 'TransactionController@bonus')->name('secure.bonus');
        Route::get('/admin/history', 'TransactionController@history')->name('secure.history');
        Route::get('/admin/history-bet', 'TransactionController@historyBet')->name('secure.history-bet');
        
        Route::get('/shr/playGame', 'GameController@playGame')->name('secure.playGame');
    });
});

Route::middleware(['auth'])->namespace('Api')->group(function () {
    Route::match(['get', 'post'], 'Account/Update.aspx/UpdateWallet', 'SeamlesWsController@getBalance2')->name('api.balance')->withoutMiddleware([Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);
});

Route::middleware(['auth'])->namespace('Frontend')->group(function () {
    Route::post('api/bank/setDeposit', 'TransactionController@posttrx')->name('secure.deposit.submit');
    Route::post('api/bank/setWithdraw', 'TransactionController@postwd')->name('secure.withdrawal.submit');
    
    Route::get('api/qr/pay_status/{trx_id}', 'TransactionController@pay_status')->name('api.payStatus');
    Route::get('api/qr/cancel_pay/{trx_id}', 'TransactionController@cancel_pay')->name('api.cancelPay');
   
    Route::post('/secure/admin/bonus/complete/{id}', 'TransactionController@completeBonus')->name('api.bonus.complete');
    Route::post('api/account/setPassword', 'UserController@update')->name('update.password')->withoutMiddleware([\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);
});

Route::namespace('Auth')->group(function () {
    Route::any('account/logout', 'LoginController@logout')->name('account.logout');
});


Route::namespace('Frontend')->group(function () {
    Route::post('account/login','HomeController@v2_acc_login')->name('api.login')->withoutMiddleware([Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);
    Route::post('account/register', 'HomeController@registers')->name('api.register')->withoutMiddleware([Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class]);
});



Auth::routes();

Route::fallback(function () {
    return view('frontend.errors.404');
});