<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

class CheckUserType
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
     */

    public function handle(Request $request, Closure $next, $routeType)
    {
        $userType = auth()->user()->userType->type_user;

        if ($routeType == 'enterWorkstation' && $userType != 'Técnico') {
            return redirect()->route('home'); // ou qualquer rota padrão para redirecionar
        }

        if ($routeType == 'home' && $userType != 'Super_Administrador') {
            return redirect()->route('enterWorkstation'); // ou qualquer rota padrão para redirecionar
        }

        return $next($request);
    }
}
