<?php

namespace App\Http\Middleware;

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

class RejectDuringMaintenance
{
    public function handle(Request $request, Closure $next): Response
    {
        if (! $request->user()?->isAdminRole() && SystemSetting::query()->value('maintenance_mode')) {
            return response()->view('public.maintenance', [], 503);
        }

        return $next($request);
    }
}
