<?php

namespace App\Http\Middleware;

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

class EnsureModulePermission
{
    public function handle(Request $request, Closure $next, string $module): Response
    {
        abort_unless($request->user()?->canAccessModule($module), 403, 'You do not have permission to access this module.');

        return $next($request);
    }
}
