<?php

namespace App\Http\Middleware;

use App\Models\Setting;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureModuleEnabled
{
    public function handle(Request $request, Closure $next, string $key, string $default = '1'): Response
    {
        abort_unless(Setting::valueFor($key, $default) === '1', 403);

        return $next($request);
    }
}
