<?php

namespace App\Http\Middleware;

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

class EnsureInstalled
{
    public function handle(Request $request, Closure $next): Response
    {
        if (app()->environment('testing')) {
            return $next($request);
        }

        if (! InstallLock::exists() && ! $request->is('install*')) {
            return redirect()->route('install.welcome');
        }

        return $next($request);
    }
}
