<?php

namespace App\Modules\Settings\Rbac\Middleware;

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

class EnsureTenantPermission
{
    public function handle(Request $request, Closure $next, string $permission): Response
    {
        $user = $request->user();
        if ($user === null || ! $user->can($permission)) {
            abort(403);
        }

        return $next($request);
    }
}
