<?php

namespace Core\Middleware;

use Core\Auth;
use Core\Response;

class ManagerMiddleware implements MiddlewareInterface
{
    /**
     * Handles the middleware logic to check for 'manager' or 'super_admin' roles.
     *
     * @return bool True if the user is authorized, false otherwise.
     */
    public function handle(string $uri, string $method, array $params): bool
    {
        $user = Auth::user();

        // Check if the user is authenticated and has a manager or super admin role
        if ($user && $user['role'] === 'manager') {
            echo 'yes';
            return true;
        }

        // If not authorized, abort the request with a 403 Forbidden status
        Response::abort(403);
        return false;
    }
}
