<?php

namespace Modules\Admin\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Gate;
use Modules\User\Models\User;
use Modules\User\Models\Role;

class PostCreatePolicyAuthorization
{
    public function handle(Request $request, Closure $next): Response
    {
        if (!Auth::user()->can('viewAdminPath', User::class) && !Auth::user()->hasRole(Role::CITY_MANAGER))
        {
            abort(403, 'Unauthorized action.');
        }

        return $next($request);
    }
}