<?php

namespace App\Http\Middleware;

use App\Services\PermissionService;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class EnsurePermission
{
    public function handle(Request $request, Closure $next, string $permission): Response
    {
        if (! app(PermissionService::class)->userCan($request->user(), $permission)) {
            abort(403, 'این مجوز برای شما فعال نیست.');
        }

        return $next($request);
    }
}
