<?php

namespace WordpressModels\Rest\Permissions;

use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;

class AuthorizationExpressionFunctionProvider implements ExpressionFunctionProviderInterface
{

    public function __construct(private readonly PermissionFunctionsInterface $permissionFunctions)
    {
    }

    public function compileIsLoggedIn(): string
    {
        $class = $this->permissionFunctions::class;
        return "$class::isAuthorized()";
    }

    public function evaluateisLoggedIn(): bool
    {
        return $this->permissionFunctions::isAuthorized();
    }

    public function getFunctions(): array
    {
        return [
            new ExpressionFunction('is_authorized',
                $this->compileIsLoggedIn(...),
                $this->evaluateisLoggedIn(...)),
        ];
    }
}