<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class CheckFrozen
{
    public function handle(Request $request, Closure $next): Response
    {
        if ($request->user() && $request->user()->isFrozen()) {
            if (! in_array($request->method(), ['GET', 'HEAD'])) {
                return response()->json([
                    'status'  => false,
                    'message' => 'Your account is frozen. You have view-only access.',
                ], 403);
            }
        }

        return $next($request);
    }
}
