<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        api: __DIR__.'/../routes/api.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )

    // ✅ Middleware
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->web(append: [
    \App\Http\Middleware\CheckMaintenance::class,
]);

        $middleware->alias([
            'admin' => \App\Http\Middleware\AdminOnly::class,
            'adminip' => \App\Http\Middleware\AdminIPWhitelist::class,
            'api_key' => \App\Http\Middleware\ApiKeyMiddleware::class,
            

        ]);

        // 🚫 Nonaktifkan CSRF untuk route callback PGA VIP
        // Ini cara resmi Laravel 12 (pengganti VerifyCsrfToken.php)
        $middleware->validateCsrfTokens(except: [
            'callback/pga',
            'api/callback/pga',
                'telegram/webhook',
                'payment/tokopay/callback',
                'telegram/fixmerah/webhook',
        ]);
    })

    // ✅ Handler exception
    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })
->withCommands([
    \App\Console\Commands\CheckOtpCommand::class,
    
])
->withCommands([
    \App\Console\Commands\OtpWorker::class,
])

->withCommands([
    \App\Console\Commands\CleanupInactiveUsers::class,
])

    ->create();
