<?php

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

// Guest Routes
Route::middleware('guest')->group(function () {
    Route::get('/admin/login', [AuthController::class, 'showLogin'])->name('admin.login');
    Route::post('/admin/login', [AuthController::class, 'login'])->name('admin.login.post');
});

// Admin Authentication Required Routes
Route::middleware('admin.auth')->group(function () {
    // Root redirects to admin dashboard
    Route::get('/', function () {
        return redirect()->route('admin.dashboard');
    });
    
    // Wallet & Client management dashboard
    Route::get('/admin/dashboard', [DashboardController::class, 'index'])->name('admin.dashboard');
    Route::post('/admin/clients', [DashboardController::class, 'storeClient'])->name('clients.store');
    Route::post('/admin/clients/recharge', [DashboardController::class, 'recharge'])->name('clients.recharge');
    
    // Clients list index & data feeds (Yajra DataTables)
    Route::get('/admin/clients', [DashboardController::class, 'clientsIndex'])->name('admin.clients');
    Route::get('/admin/clients/data', [DashboardController::class, 'clientsData'])->name('admin.clients.data');
    Route::get('/admin/clients/{id}/recharges', [DashboardController::class, 'rechargeHistory'])->name('admin.clients.recharges');
    Route::get('/admin/recharges/{id}/invoice', [DashboardController::class, 'showInvoice'])->name('admin.recharges.invoice');
    Route::post('/admin/recharges/{id}/send-invoice', [DashboardController::class, 'sendInvoiceEmail'])->name('admin.recharges.send-invoice');

    // Verification Logs (Datatables page)
    Route::get('/admin/verifications', [VerificationController::class, 'index'])->name('admin.verifications');
    Route::get('/admin/logs/data', [VerificationController::class, 'data'])->name('admin.logs.data');
    Route::get('/admin/logs/{id}', [VerificationController::class, 'show'])->name('admin.logs.show');

    // Admin Logout
    Route::post('/admin/logout', [AuthController::class, 'logout'])->name('admin.logout');
    
    // Change password (no old password required)
    Route::post('/admin/password/change', [AuthController::class, 'changePassword'])->name('admin.password.change');
});

// Zoho Mock Payment Gateway routes (Public)
Route::get('/zoho/mock-checkout/{recharge_id}', [\App\Http\Controllers\Api\WidgetWalletController::class, 'mockCheckout'])->name('zoho.mock-checkout');
Route::post('/zoho/mock-checkout/{recharge_id}/complete', [\App\Http\Controllers\Api\WidgetWalletController::class, 'completeMockCheckout'])->name('zoho.mock-checkout.complete');
Route::get('/zoho/callback', [\App\Http\Controllers\Api\WidgetWalletController::class, 'zohoCallback'])->name('zoho.callback');
