<?php

use Illuminate\Support\Facades\Route;

Route::middleware('ip.lookup')->group(function () {
    Route::get('oauth/google', [\App\Http\Controllers\OauthController::class, 'redirectToProvider'])->name('oauth.google');  
    Route::get('oauth/google/callback', [\App\Http\Controllers\OauthController::class, 'handleProviderCallback'])->name('oauth.google.callback');
});
Route::get('/cron/update-price', [\App\Http\Controllers\CronController::class, 'updateCryptoPrices']);
Route::get('/cron/daily', [\App\Http\Controllers\CronController::class, 'daily']);

Route::get('/sitemap.xml', [\App\Http\Controllers\SitemapController::class, 'index'])->name('sitemap');

Route::get('/contest', [\App\Http\Controllers\ContestController::class, 'index']);
Route::get('/contest/{id}/winners', [\App\Http\Controllers\ContestController::class, 'getWinners']);

Route::get('/captcha', [\App\Http\Controllers\CaptchaController::class, 'index'])->name('captcha.index');
Route::get('/cc/{action}', [\App\Http\Controllers\CaptchaController::class, 'action'])->where('action', '.*');
Route::post('/cc/{action}', [\App\Http\Controllers\CaptchaController::class, 'action'])->where('action', '.*');

Route::post('/webhook/deposit', [\App\Http\Controllers\WebhookController::class, 'handleDepositWebhook']);
Route::post('/webhook/faucetpay', [\App\Http\Controllers\WebhookController::class, 'faucetpay']);

Route::get('/', [\App\Http\Controllers\FrontController::class, 'index']);

Route::get('/pb/{offerwallName}', [\App\Http\Controllers\PostbackHandler::class, 'check']);
Route::post('/pb/{offerwallName}', [\App\Http\Controllers\PostbackHandler::class, 'check']);

Route::get('/blog', [\App\Http\Controllers\BlogController::class, 'index'])->name('blog.index');
Route::get('/blog/load', [\App\Http\Controllers\BlogController::class, 'load'])->name('blog.load');
Route::get('/blog/{slug}', [\App\Http\Controllers\BlogController::class, 'view'])->name('blog.view');
Route::get('/page/{slug}', [\App\Http\Controllers\PageController::class, 'view'])->name('page.view');

Route::get('/withdraw-proof', [\App\Http\Controllers\FrontController::class, 'fetchHistory']);

Route::middleware(['ip.lookup', 'auth'])->group(function () {
    Route::get('/chart/load', [\App\Http\Controllers\ChartController::class, 'loadChart']);
    Route::get('/dashboard', [\App\Http\Controllers\DashboardController::class, 'index'])->name('dashboard');
    
    Route::get('/get-balance', function () {
        return response()->json([
            'success' => true,
            'balance' => balanceAndSymbol(Auth::user()->balance)
        ]);
    })->name('user.getBalance');
    Route::get('/get-deposit', function () {
        return response()->json([
            'success' => true,
            'balance' => '<span class="flex items-center">$ <span class="ml-1">' . formatUSD(Auth::user()->available_deposit) . '</span></span>'
        ]);
    })->name('user.getDeposit');

    Route::get('/profile', [\App\Http\Controllers\ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('/profile', [\App\Http\Controllers\ProfileController::class, 'update'])->name('profile.update');
    Route::delete('/profile', [\App\Http\Controllers\ProfileController::class, 'destroy'])->name('profile.destroy');
    Route::post('/profile/enable-2fa', [\App\Http\Controllers\ProfileController::class, 'enableTwoFactor'])->name('profile.enable2FA');
    Route::post('/profile/verify-2fa', [\App\Http\Controllers\ProfileController::class, 'verifyTwoFactor'])->name('profile.verify2FA');
    Route::post('/profile/disable-2fa', [\App\Http\Controllers\ProfileController::class, 'disableTwoFactor'])->name('profile.disable2FA');


    Route::get('/notifications', [\App\Http\Controllers\NotificationController::class, 'index']);
    Route::post('/notifications', [\App\Http\Controllers\NotificationController::class, 'store']);
    Route::put('/notifications/{id}/read', [\App\Http\Controllers\NotificationController::class, 'markAsRead']);
    Route::put('/notifications/read-all', [\App\Http\Controllers\NotificationController::class, 'markAllAsRead']);
    
    Route::get('/offerwall/{offerwall}', [\App\Http\Controllers\OfferwallController::class, 'index'])->name('offerwall.index');
    Route::get('/offerwall-history/{offerwall}', [\App\Http\Controllers\OfferwallController::class, 'fetchHistory']);
    Route::get('/get-bitcotasks-ptc', [\App\Http\Controllers\OfferwallController::class, 'fetchBitcoPTC'])->middleware('throttle:withdraw');
    Route::get('/get-bitcotasks-shortlink', [\App\Http\Controllers\OfferwallController::class, 'fetchBitcoSL'])->middleware('throttle:withdraw');
    Route::get('/get-wannads-offer', [\App\Http\Controllers\OfferwallController::class, 'fetchWannadsOffer'])->middleware('throttle:withdraw');
    Route::get('/get-wannads-survey', [\App\Http\Controllers\OfferwallController::class, 'fetchWannadsSurvey'])->middleware('throttle:withdraw');
    
    
    Route::get('/faucet', [\App\Http\Controllers\FaucetController::class, 'index'])->name('faucet.index');
    Route::post('/faucet/claim', [\App\Http\Controllers\FaucetController::class, 'claimFaucet'])->name('faucet.claim');
    Route::get('/faucet/history', [\App\Http\Controllers\FaucetController::class, 'fetchHistory'])->name('faucet.history');
    
    Route::get('/links', [\App\Http\Controllers\LinksController::class, 'index'])->name('link.index');
    Route::get('/links/load', [\App\Http\Controllers\LinksController::class, 'load'])->name('link.load');
    Route::get('/link/go/{id}', [\App\Http\Controllers\LinksController::class, 'redirect'])->name('link.go');
    Route::get('/link/back/{token}', [\App\Http\Controllers\LinksController::class, 'back'])->name('link.back');
    Route::post('/link/go/{id}', [\App\Http\Controllers\LinksController::class, 'redirect'])->name('link.redirect');
    Route::get('/links/history', [\App\Http\Controllers\LinksController::class, 'fetchHistory'])->name('link.history');
    
    Route::get('/deposit', [\App\Http\Controllers\DepositController::class, 'index'])->name('deposit.index');
    Route::get('/deposit/history', [\App\Http\Controllers\DepositController::class, 'fetchHistory'])->name('deposit.history');
    
    Route::get('/address/get-symbols', [\App\Http\Controllers\AddressController::class, 'getSymbols'])->name('address.symbols');
    Route::get('/address/get-chains/{symbol}', [\App\Http\Controllers\AddressController::class, 'getChains'])->name('address.chains');
    Route::get('/address/create/{symbol}/{chain}', [\App\Http\Controllers\AddressController::class, 'getAddress'])->name('address.create');
    
    Route::get('/advertise/ptc', [\App\Http\Controllers\PtcController::class, 'advertise'])->name('ptc.advertise');
    Route::get('/advertise/ptc/load/{status}', [\App\Http\Controllers\PtcController::class, 'fetchAds']);
    Route::post('/advertise/ptc/store', [\App\Http\Controllers\PtcController::class, 'store']);
    Route::post('/advertise/ptc/update-status/{id}', [\App\Http\Controllers\PtcController::class, 'updateStatus']);

    Route::get('/advertise/link', [\App\Http\Controllers\LinksController::class, 'advertise'])->name('link.advertise');
    Route::get('/advertise/link/load/{status}', [\App\Http\Controllers\LinksController::class, 'fetchAds']);
    Route::post('/advertise/link/store', [\App\Http\Controllers\LinksController::class, 'store']);
    Route::post('/advertise/link/update-status/{id}', [\App\Http\Controllers\LinksController::class, 'updateStatus']);

    Route::get('/ptc', [\App\Http\Controllers\PtcController::class, 'index'])->name('ptc.index');
    Route::get('/ptc/load', [\App\Http\Controllers\PtcController::class, 'load'])->name('ptc.load');
    Route::get('/ptc/history', [\App\Http\Controllers\PtcController::class, 'fetchHistory'])->name('ptc.history');
    Route::get('/ptc/view/{id}', [\App\Http\Controllers\PtcController::class, 'view'])->name('ptc.view');
    Route::post('/ptc/view/{id}', [\App\Http\Controllers\PtcController::class, 'view']);
    Route::post('/ptc/verify/{token}', [\App\Http\Controllers\PtcController::class, 'verify'])->name('ptc.verify');
    
    Route::get('/withdraw/get-rate', [\App\Http\Controllers\WithdrawController::class, 'getRate']);
    Route::post('/withdraw/process-withdraw', [\App\Http\Controllers\WithdrawController::class, 'processWithdraw'])
            ->middleware('throttle:withdraw');
    Route::get('/withdraw/history', [\App\Http\Controllers\WithdrawController::class, 'fetchHistory']);
    
    Route::get('/referrals', [\App\Http\Controllers\ReferralController::class, 'index']);
    Route::get('/referrals/history', [\App\Http\Controllers\ReferralController::class, 'fetchHistory']);
    
});

require __DIR__.'/auth.php';
require __DIR__.'/admin.php';
