<?php

namespace App\Http\Middleware;

use App\Support\InstallationState;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureInstalled
{
    public function __construct(
        private readonly InstallationState $installationState,
    ) {}

    public function handle(Request $request, Closure $next): Response
    {
        if (! $this->installationState->isInstalled()) {
            return redirect()->route('installer.welcome');
        }

        return $next($request);
    }
}
