<?php

namespace Src\Modules\Auth\Infrastructure\Storage;

use Src\Modules\Auth\Interfaces\Infrastructure\Storage\IFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\Storage\IAdminsStorage;

class Factory implements IFactory {

    private IInfrastructureFactory $infrastructureFactory;

    private ?IAdminsStorage $adminsStorage = null;

    public function setInfrastructureFactory(IInfrastructureFactory $factory): void
    {
        $this->infrastructureFactory = $factory;
    }

    public function getInfrastructureFactory(): IInfrastructureFactory
    {
        return $this->infrastructureFactory;
    }
    
    public function getAdminsStorage(): AdminsStorage
    {
        if($this->adminsStorage){
            return $this->adminsStorage;
        }
        $this->adminsStorage = new AdminsStorage();
        $adminsQuery = $this->infrastructureFactory->getQueriesFactory()->createAdminsQuery();
        $this->adminsStorage->setAdminsQuery($adminsQuery);
        return $this->adminsStorage;
    }

}