<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use App\Http\Middleware\CheckCompanyActive;
use App\Http\Middleware\CheckConcurrentUsers;
use App\Http\Middleware\EnsurePasswordChanged;
use App\Http\Middleware\StampCompanySession;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web:      __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health:   '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        // Append to all web requests — stamps session rows with company/user IDs
        $middleware->web(append: [
            StampCompanySession::class,
        ]);

        // Named middleware aliases used in routes
        $middleware->alias([
            'company.active'   => CheckCompanyActive::class,
            'concurrent.users' => CheckConcurrentUsers::class,
            'password.changed' => EnsurePasswordChanged::class,
        ]);
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();
