<?php

namespace App\Http\Middleware;

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

class DriverMiddleware
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, Closure $next): Response
    {
        $user = auth()->user();

        if (!$user || $user->role !== 'driver') {
            return response()->json([
                'success' => false,
                'message' => 'Access denied. Only drivers can access this resource.',
            ], 403);
        }

        return $next($request);
    }
}
