<?php

use App\Http\Controllers\Api\AuthController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    return redirect()->route('admin.dashboard');
});

// Email verification public link handler
Route::get('/email/verify/{id}/{hash}', [AuthController::class, 'verify'])
    ->name('verification.verify');

// Web-based password reset flows
Route::get('/password/reset/{token}', function (Request $request, $token) {
    return view('auth.reset-password', [
        'token' => $token,
        'email' => request()->email
    ]);
})->name('password.reset');

Route::post('/password/reset', [AuthController::class, 'webResetPassword'])
    ->name('password.update');

Route::get('/password/reset-success', function () {
    return view('auth.reset-success');
})->name('password.reset-success');

// Flutterwave redirect handler
Route::get('/payment/callback', function (\Illuminate\Http\Request $request) {
    return view('payment.callback', [
        'status' => $request->query('status'),
        'tx_ref' => $request->query('tx_ref'),
        'amount' => $request->query('amount'),
        'currency' => $request->query('currency'),
    ]);
});

// ─── ADMIN PORTAL ROUTES ──────────────────────────────────────────────────
use App\Http\Controllers\AdminController;

Route::get('/admin/login', [AdminController::class, 'showLogin'])->name('admin.login');
Route::post('/admin/login', [AdminController::class, 'login']);
Route::get('/admin/logout', [AdminController::class, 'logout'])->name('admin.logout');

Route::group([], function () {
    Route::get('/admin', [AdminController::class, 'index'])->name('admin.dashboard');
    
    // VIP Packages CRUD
    Route::post('/admin/vip-packages', [AdminController::class, 'storePackage'])->name('admin.packages.store');
    Route::put('/admin/vip-packages/{package}', [AdminController::class, 'updatePackage'])->name('admin.packages.update');
    Route::delete('/admin/vip-packages/{package}', [AdminController::class, 'deletePackage'])->name('admin.packages.delete');
    
    // Match Predictions CRUD
    Route::post('/admin/predictions', [AdminController::class, 'storePrediction'])->name('admin.predictions.store');
    Route::put('/admin/predictions/{prediction}', [AdminController::class, 'updatePrediction'])->name('admin.predictions.update');
    Route::patch('/admin/predictions/{prediction}/status', [AdminController::class, 'updatePredictionStatus'])->name('admin.predictions.status');
    Route::delete('/admin/predictions/{prediction}', [AdminController::class, 'deletePrediction'])->name('admin.predictions.delete');
    
    // Users & Subscriptions
    Route::post('/admin/users/{user}/subscription', [AdminController::class, 'updateSubscription'])->name('admin.users.subscription');
    
    // Support Tickets
    Route::post('/admin/tickets/{ticket}/reply', [AdminController::class, 'replyTicket'])->name('admin.tickets.reply');
    
    // Settings
    Route::post('/admin/settings', [AdminController::class, 'updateSettings'])->name('admin.settings.update');

    // Withdrawals
    Route::post('/admin/withdraw/validate', [AdminController::class, 'validateWithdraw'])->name('admin.withdraw.validate');
    Route::post('/admin/withdraw/confirm', [AdminController::class, 'confirmWithdraw'])->name('admin.withdraw.confirm');

    // Notifications
    Route::post('/admin/notifications/send', [AdminController::class, 'sendNotification'])->name('admin.notifications.send');
});


