<?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',
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Stateless API - No SPA stateful middleware needed
        $middleware->validateCsrfTokens(except: [
            'webhooks/paystack',
        ]);

        // Global middleware for tenant identification from domain/subdomain
        $middleware->append(\App\Http\Middleware\IdentifyTenantByDomain::class);

        // Named middleware aliases
        $middleware->alias([
            'association.admin' => \App\Http\Middleware\EnsureAssociationAdmin::class,
            'module.check' => \App\Http\Middleware\CheckModuleAccess::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();
