<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class RoleMiddleware
{
    public function handle(Request $request, Closure $next, string ...$roles): mixed
    {
        if (!$request->user() || !in_array($request->user()->role, $roles)) {
            return response()->json(['success' => false, 'message' => 'Unauthorized. Insufficient permissions.'], 403);
        }
        return $next($request);
    }
}
