<?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',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->alias([
            'admin' => \App\Http\Middleware\AdminMiddleware::class,
            'vendor.auth' => \App\Http\Middleware\VendorMiddleware::class,
            'vendor' => \App\Http\Middleware\VendorMiddleware::class,
            'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
            'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
            'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
            'installed' => \App\Http\Middleware\CheckInstallation::class,
            'setlocale' => \App\Http\Middleware\SetLocale::class,
        ]);
        
        $middleware->web([
            \App\Http\Middleware\SetLocale::class,
            \App\Http\Middleware\ShareCurrency::class,
        ]);
        
        // Don't apply CheckInstallation to install routes
        $middleware->validateCsrfTokens(except: [
            'install/*',
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();
