<?php

use App\Http\Controllers\Admin\CardController as AdminCardController;
use App\Http\Controllers\Admin\CreditDebitController;
use App\Http\Controllers\Admin\DashboardController as AdminDashboard;
use App\Http\Controllers\Admin\LoanController as AdminLoanController;
use App\Http\Controllers\Admin\TransferController as AdminTransferController;
use App\Http\Controllers\Admin\SettingController;
use App\Http\Controllers\Admin\UserController as AdminUserController;
use App\Http\Controllers\Admin\UserTransferSettingController;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\MailController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\User\CardController;
use App\Http\Controllers\User\DepositController;
use App\Http\Controllers\User\LoanController;
use App\Http\Controllers\User\ProfileController;
use App\Http\Controllers\User\TicketController;
use App\Http\Controllers\User\UserController;
use App\Http\Controllers\User\TransferController;
use App\Http\Controllers\User\WithdrawalController;
use App\Http\Controllers\User\TransactionController;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Route;

Route::get('/', [PageController::class,'index'])->name('landing.welcome');
Route::get('/accounts', [PageController::class,'accounts'])->name('landing.accounts');
Route::get('/about', [PageController::class,'about'])->name('landing.about');
Route::get('/loan', [PageController::class,'loan'])->name('landing.loan');
Route::get('/contact', [PageController::class,'contact'])->name('landing.contact');
Route::post('/landing/contact/form',[MailController::class,'contact']);


Route::get('/secure/forgot-password', [AuthController::class,'resetPage'])->name('reset');
Route::post('/secure/forgot-password/create', [AuthController::class,'resetCreate']);
Route::get('/secure/reset-password/{token}', [AuthController::class,'resetLink'])->name('password.reset');
Route::post('/secure/change-password', [AuthController::class,'reset']);



Route::group(['middleware'=> 'guest'], function () {

    Route::get('/secure/agreement', [PageController::class,'agreement'])->name('agreement');
    Route::get('/secure/onlineapplication', [PageController::class,'signup'])->name('register');
    Route::get('secure/pin-authentication', [PageController::class,'authentication'])->name('authentication');
    Route::post('/secure/onlineapplication', [AuthController::class,'register']);
    Route::get('/secure/login', [PageController::class,'login'])->name('user.login');
    Route::get('/secure/admin-login', [PageController::class,'adminLogin'])->name('admin.login');
    Route::post('secure/login', [AuthController::class,'login']);
    Route::post('/secure/pin-authentication', [AuthController::class,'authenticate']);
    Route::get('/secure/success', [PageController::class,'authSuccess']);
    Route::get('secure/verify/{token}', [UserController::class,'verify'])->where(['token'=>'.*']);

});


Route::group(['prefix'=>'user', 'middleware'=> ['IsUser']], function () {

    Route::get('dashboard', [UserController::class,'index'])->name('user.dashboard');
    Route::get('transfer/local', [TransferController::class, 'local'])->name('user.transfer.local');
    Route::get('transfer/international', [TransferController::class, 'international'])->name('user.transfer.international');
    Route::post('transfer', [TransferController::class,'transfer']);
    Route::post('transfer/otp', [TransferController::class,'otp']);
    Route::post('transfer/tax', [TransferController::class,'tax']);
    Route::post('transfer/imf', [TransferController::class,'imf']);
    Route::post('transfer/cot', [TransferController::class,'cot']);
    Route::post('transfer/complete', [TransferController::class,'complete']);
    Route::get('transfer/success', [TransferController::class,'success']);
    Route::get('deposit/bank', [DepositController::class,'bank'])->name('user.deposit.bank');
    Route::get('deposit/blockchain', [DepositController::class,'blockchain'])->name('user.deposit.blockchain');
    Route::post('deposit/create', [DepositController::class,'create']);
    Route::get('/withdrawal/bank', [WithdrawalController::class,'bank'])->name('user.withdrawal.bank');
    Route::get('/withdrawal/transfer', [WithdrawalController::class,'transfer'])->name('user.withdrawal.transfer');
    Route::get('/withdrawal/crypto', [WithdrawalController::class,'crypto'])->name('user.withdrawal.crypto');
    Route::post('withdrawal/crypto/create', [WithdrawalController::class,'createCrypto']);
    Route::post('withdrawal/normal/create', [WithdrawalController::class,'createNormal']);
    Route::get('profile', [ProfileController::class,'index'])->name('user.profile');
    Route::get('profile/get', [ProfileController::class,'show']);
    Route::patch('profile/update', [ProfileController::class,'update']);
    Route::patch('profile/nextofkin/update', [ProfileController::class,'updateNextOfKin']);
    Route::post('profile/photo/update', [ProfileController::class,'updatePhoto']);
    Route::patch('profile/password/change', [ProfileController::class,'changePassword']);
    Route::patch('profile/pin/change', [ProfileController::class,'changePin']);
    Route::get('statement', [TransactionController::class,'index'])->name('user.statement');
    Route::get('/statement/load', [TransactionController::class,'loadStatement']);
    Route::get('statement/print', [TransactionController::class,'show'])->name('user.statement.print');
    Route::get('open-ticket', [TicketController::class,'index'])->name('user.open-ticket');
    Route::post('open-ticket', [TicketController::class,'store']);
    Route::get('tickets', [TicketController::class,'show'])->name('user.tickets');
    Route::get('tickets/{id}', [TicketController::class,'display'])->name('user.show-ticket');
    Route::get('apply-loan', [LoanController::class,'index'])->name('user.apply-loan');
    Route::post('loan/apply', [LoanController::class,'store']);
    Route::get('loans', [LoanController::class,'show'])->name('user.loans');
    Route::get('cards', [CardController::class,'index'])->name('user.cards');
    Route::get('apply-card', [CardController::class,'create'])->name('user.apply-card');
    Route::post('apply-card', [CardController::class,'store']);

});


Route::group(['prefix'=>'admin','middleware'=> ['IsAdmin']], function () {

    Route::get('dashboard',[AdminDashboard::class,'index'])->name('admin.dashboard');
    Route::get('users',[AdminUserController::class,'index'])->name('admin.users');
    Route::get('users/load',[AdminUserController::class,'load']);
    Route::get('users/count',[AdminUserController::class,'stats']);
    Route::post('user/add',[AdminUserController::class,'store']);
    Route::patch('user/update',[AdminUserController::class,'update']);
    Route::post('user/photo/update',[AdminUserController::class,'updatePhoto']);
    Route::post('user/delete',[AdminUserController::class,'destroy']);
    Route::patch('user/password',[AdminUserController::class,'updateUserPassword']);
    Route::patch('user/fund',[AdminUserController::class,'addFunds']);
    Route::get('/user/get',[AdminUserController::class,'getUser']);
    Route::patch('user/toggle',[AdminUserController::class,'toggleUser']);
    Route::patch('user/strength',[AdminUserController::class,'toggleUserStrength']);
    Route::post('/mail/single', [MailController::class, 'singleMail']);


    Route::get('transfers',[AdminTransferController::class,'index'])->name('admin.transfers');
    Route::get('transfer/count',[AdminTransferController::class,'count']);
    Route::get('transfers/load',[AdminTransferController::class,'show']);
    Route::patch('transfer/toggle',[AdminTransferController::class,'update']);
    Route::get('transfer/settings',[UserTransferSettingController::class,'index'])->name('admin.users.transfer.codes');
    Route::get('transfer/settings/load',[UserTransferSettingController::class,'show']);
    Route::post('transfer/set-count',[UserTransferSettingController::class,'setUserTransferCount']);
    Route::patch('transfer/update-count',[UserTransferSettingController::class,'updateUserTransferCount']);
    Route::post('transfer/set-amount',[UserTransferSettingController::class,'setUserTransferAmount']);
    Route::patch('transfer/update-amount',[UserTransferSettingController::class,'updateUserTransferAmount']);
    Route::patch('transfer/first-transfer',[UserTransferSettingController::class,'firstTransfer']);
    Route::patch('imf/generate',[UserTransferSettingController::class,'generateImf']);


    Route::get('settings',[SettingController::class,'index'])->name('admin.settings.general');
    Route::patch('settings/general/update',[SettingController::class,'updateGeneral']);
    Route::patch('settings/loan/update',[SettingController::class,'updateLoan']);
    Route::patch('settings/transfer/update',[SettingController::class,'updateTransfer']);


    Route::get('cards',[AdminCardController::class,'index'])->name('admin.cards');
    Route::get('cards/load',[AdminCardController::class,'show']);
    Route::patch('card/toggle',[AdminCardController::class,'update']);
    Route::get('loans',[AdminLoanController::class,'index'])->name('admin.loans');
    Route::get('loans/load',[AdminLoanController::class,'show']);
    Route::patch('loan/toggle',[AdminLoanController::class,'update']);



    Route::get('credit-debit',[CreditDebitController::class,'index'])->name('admin.credit-debit');
    Route::post('credit-debit', [CreditDebitController::class,'store'])->name('admin.add.debit-credit');


    Route::get('/settings/clear',function(){

        Artisan::call('cache:clear');
        Artisan::call('config:clear');
        Artisan::call('view:clear');

        return back()->with('Site Cache Cleared!');

    })->name('admin.cache.clear');

});


Route::get('logout', [AuthController::class,'logout'])->name('logout');
// base_path('route/others/guest.php');
// base_path('route/others/user.php');
// base_path('route/others/admin.php');
