<?php

namespace App\Http\Middleware;

use App\Enums\AccountStatus;
use App\Models\Role;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class OrganizerApproved
{
    public function handle(Request $request, Closure $next): Response
    {
        $user = $request->user();
        if ($user === null) {
            return $next($request);
        }

        if (! $user->hasRole(Role::SLUG_ORGANIZADOR)) {
            return $next($request);
        }

        if ($user->account_status === AccountStatus::Approved) {
            return $next($request);
        }

        return redirect()->route('dashboard.organizer.account-status');
    }
}
