<?php

namespace App\Http\Middleware;

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

class EnsureUserIsApproved
{
    public function handle(Request $request, Closure $next): Response
    {
        if (!$request->user()) {
            return redirect()->route('login');
        }

        if (in_array($request->user()->status, ['pending', 'rejected'])) {
            return redirect()->route('portal.pending');
        }

        return $next($request);
    }
}
