<?php

namespace Src\Modules\Auth\Infrastructure\PersistLayer;

use Src\Modules\Auth\Interfaces\Infrastructure\PersistLayer\IFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\PersistLayer\IAdminsLayer;
use Src\Modules\Auth\Interfaces\IFactory as IModuleFactory;

class Factory implements IFactory {

    private IInfrastructureFactory $infrastructureFactory;

    private ?IAdminsLayer $adminsLayer = null;

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

    public function getInfrastructureFactory(): IInfrastructureFactory
    {
        return $this->infrastructureFactory;
    }
    
    public function getAdminsLayer(): AdminsLayer
    {
        if($this->adminsLayer){
            return $this->adminsLayer;
        }
        $this->adminsLayer = new AdminsLayer();
        $table = $this->infrastructureFactory->getModuleFactory()->getSetting(IModuleFactory::ADMINS_TABLE);
        $this->adminsLayer->setTable($table);
        return $this->adminsLayer;
    }

}