<?php

use App\Http\Middleware\CheckPermission;
use App\Http\Middleware\CheckTenantSubscription;
use App\Http\Middleware\EnforceTenantScope;
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) {
        // The local XAMPP app can be shared through a loopback reverse proxy
        // (for example, Cloudflare Tunnel). Trust only that local hop so
        // Laravel generates HTTPS URLs from the forwarded request scheme.
        $middleware->trustProxies(at: ['127.0.0.1', '::1']);

        $middleware->alias([
            'permission' => CheckPermission::class,
            'tenant.subscription' => CheckTenantSubscription::class,
            'tenant.scope' => EnforceTenantScope::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();
