<?php

namespace App\Modules\Core\Middleware;

use App\Http\Responses\ApiResponse;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsureSuperAdmin
{
    /**
     * @param Closure(Request): Response $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        if (! $request->user()?->hasRole('super-admin')) {
            return ApiResponse::error('Super admin access required', 403);
        }

        return $next($request);
    }
}
