<?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): void {
        $middleware->web(prepend: [
            \App\Http\Middleware\UseSystemSessionCookieForLivewireRequests::class,
        ]);

        $middleware->alias([
            'ensure-correct-guard' => \App\Http\Middleware\EnsureCorrectGuard::class,
            'ensure-platform-capability' => \App\Http\Middleware\EnsurePlatformCapability::class,
            'ensure-workspace-member' => \App\Http\Middleware\EnsureWorkspaceMember::class,
            'ensure-workspace-selected' => \App\Http\Middleware\EnsureWorkspaceSelected::class,
            'ensure-filament-tenant-selected' => \App\Support\Middleware\EnsureFilamentTenantSelected::class,
        ]);

        $middleware->prependToPriorityList(
            \Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests::class,
            \App\Http\Middleware\EnsureCorrectGuard::class,
        );

        $middleware->redirectGuestsTo('/admin/login');
    })
    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })->create();
