<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\UserController;

// ============================================
// Admin Authentication Routes (no auth needed)
// ============================================
Route::prefix('admin')->name('admin.')->group(function () {
    Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('login.submit');
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
});

// ============================================
// API Routes (Paystack, payments, etc.)
// ============================================
Route::prefix('api/v1')->name('api.')->group(function () {
    Route::post('/paystack/initialize', [\App\Http\Controllers\Api\PaystackController::class, 'initialize'])->name('paystack.initialize');
    Route::get('/paystack/verify/{reference}', [\App\Http\Controllers\Api\PaystackController::class, 'verify'])->name('paystack.verify');
    Route::post('/paystack/webhook', [\App\Http\Controllers\Api\PaystackController::class, 'webhook'])->name('paystack.webhook');
    Route::get('/paystack/banks', [\App\Http\Controllers\Api\PaystackController::class, 'getBanks'])->name('paystack.banks');
    Route::post('/payments/create-intent', function() {
        return response()->json(['client_secret' => 'placeholder']);
    })->name('payments.create-intent');
});

// ============================================
// Protected Admin Routes (auth required)
// ============================================
Route::prefix('admin')->name('admin.')->middleware('admin.auth')->group(function () {
    // Dashboard
    Route::get('/', [DashboardController::class, 'index'])->name('dashboard');


    // Users
    Route::get('/users', [UserController::class, 'index'])->name('users');
    Route::get('/users/{user}', [UserController::class, 'show'])->name('users.show');
    Route::post('/users/{user}/toggle-status', [UserController::class, 'toggleStatus'])->name('users.toggle-status');

    // Drivers
    Route::get('/drivers', [UserController::class, 'drivers'])->name('drivers');
    Route::post('/drivers/{driver}/verify', [UserController::class, 'verifyDriver'])->name('drivers.verify');
    Route::post('/drivers/{driver}/reject', [UserController::class, 'rejectDriver'])->name('drivers.reject');

    // God's Eye
    Route::get('/gods-eye', [DashboardController::class, 'godsEye'])->name('gods-eye');
    Route::post('/gods-eye/{deviation}/acknowledge', [DashboardController::class, 'acknowledgeDeviation'])->name('gods-eye.acknowledge');
    Route::post('/gods-eye/{deviation}/escalate', [DashboardController::class, 'escalateDeviation'])->name('gods-eye.escalate');
    Route::post('/gods-eye/{alert}/resolve', [DashboardController::class, 'resolveAlert'])->name('gods-eye.resolve');

    // Heat Map
    Route::get('/heat-map', [DashboardController::class, 'heatMap'])->name('heat-map');
});
