<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Http\Request;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        api: __DIR__.'/../routes/api.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware): void {
        $middleware->encryptCookies(except: ['xf_session','xf_user','xf_csrf','xf_style_variation','activity_filters']);
        $middleware->alias([
            'xf.auth' => \App\Http\Middleware\CheckXenForoPermissions::class,
        ]);
        $middleware->redirectGuestsTo(function(Request $request): void {
            if( $request->is('manage*'))
                abort(403);
        });
        $middleware->append(\App\Http\Middleware\CheckXenForoUserState::class);
    })
    ->withExceptions(function (Exceptions $exceptions): void {
        //
    })->create();
