<?php

namespace domain\User\User;

use domain\_\AbstractManager;

class AuthorizationChecker extends AbstractManager
{
    protected UserSolver $userSolver;

    public function loadDependencies(): void
    {
        $this->userSolver = $this->loadService(UserSolver::class);
    }

    public function isGrantedAsAdministrator(User $user = null): bool
    {
        if(!$user) {
            return false;
        }

        return $this->userSolver->isStatusAdministrator($user);
    }

    public function isGrantedAsProducer(User $user = null): bool
    {
        if(!$user) {
            return false;
        }

        return $this->isGrantedAsAdministrator($user)
            || $this->userSolver->isStatusProducer($user);
    }

    public function isGrantedAsUser(User $user = null): bool
    {
        if(!$user) {
            return false;
        }

        return $this->isGrantedAsProducer($user)
            || $this->userSolver->isStatusUser($user);
    }
}