<?php

namespace App\Http\Middleware;

use App\Exceptions\ProhibitedAction;
use App\Models\User;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use function Laravel\Prompts\error;
use App\Models\SafetyAndPrivacy;


class CheckAxisTypeMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
     * @throws ProhibitedAction
     */
    public function handle(Request $request, Closure $next): Response
    {
        $s = $request->route('safetyAndPrivacy');

        if (($s->step == 3 || $s->step == 2) && is_null($s->axis_type_id))
        {
            throw new ProhibitedAction('ابتدا نوع محور را مشخص کنید');
        }

        return $next($request);
    }
}
