<?php

use App\Http\Middleware\Installed;
use App\Http\Middleware\VerifyEmail;
use App\Http\Middleware\Authenticate;
use App\Http\Middleware\Localization;
use Illuminate\Foundation\Application;
use App\Http\Middleware\ApiKeyMiddleware;
use Spatie\Permission\Middleware\RoleMiddleware;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Spatie\Permission\Middleware\PermissionMiddleware;
use Spatie\Permission\Middleware\RoleOrPermissionMiddleware;

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

        $middleware->validateCsrfTokens(
            except: [
                '/payment/sslcommerz/*',
                '/payment/paytm/*',
                '/payment/cashfree/*',
                '/payment/phonepe/*',
                '/payment/iyzico/*',
                '/payment/pesapal/*'
            ]
        );
        $middleware->alias([
            'auth'               => Authenticate::class,
            'auth.basic'         => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
            'auth.session'       => \Illuminate\Session\Middleware\AuthenticateSession::class,
            'cache.headers'      => \Illuminate\Http\Middleware\SetCacheHeaders::class,
            'can'                => \Illuminate\Auth\Middleware\Authorize::class,
            'password.confirm'   => \Illuminate\Auth\Middleware\RequirePassword::class,
            'throttle'           => \Illuminate\Routing\Middleware\ThrottleRequests::class,
            'verified'           => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
            'apiKey'             => ApiKeyMiddleware::class,
            'verify.api'         => VerifyEmail::class,
            'installed'          => Installed::class,
            'role'               => RoleMiddleware::class,
            'permission'         => PermissionMiddleware::class,
            'role_or_permission' => RoleOrPermissionMiddleware::class,
            'localization'       => Localization::class
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();