<?php

namespace App\Http\Middleware;

use App\Enums\CoachStatus;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureCoachIsApproved
{
    /**
     * روی route group های /coach/* (به‌جز خودِ صفحه‌ی «در انتظار تأیید») اعمال می‌شود.
     */
    public function handle(Request $request, Closure $next): Response
    {
        $coach = $request->user()?->coach;

        if (! $coach || $coach->status !== CoachStatus::Approved) {
            return redirect()->route('coach.pending');
        }

        return $next($request);
    }
}
