<?php

use App\Http\Middleware\EnsureInstalled;
use App\Http\Middleware\EnsureInstallerProgress;
use App\Http\Middleware\EnsureNotInstalled;
use App\Http\Middleware\UseInstallerSession;
use App\Http\Middleware\ValidateLicense;
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',
    )
    ->withCommands([
        \App\Console\Commands\ResetInstallationCommand::class,
    ])
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->prependToGroup('web', UseInstallerSession::class);

        $middleware->alias([
            'installed' => EnsureInstalled::class,
            'not.installed' => EnsureNotInstalled::class,
            'installer.session' => UseInstallerSession::class,
            'installer.progress' => EnsureInstallerProgress::class,
            'license' => ValidateLicense::class,
            'registration.enabled' => \App\Http\Middleware\EnsureRegistrationEnabled::class,
            'staff' => \App\Http\Middleware\EnsureStaffUser::class,
            'active.user' => \App\Http\Middleware\EnsureActiveUser::class,
            'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
            'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
            'role_or_permission' => \Spatie\Permission\Middleware\RoleOrPermissionMiddleware::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })->create();
