<?php

namespace Src\Modules\Auth\Infrastructure;

use Src\Modules\Auth\Interfaces\Infrastructure\IFactory;
use Src\Modules\Auth\Interfaces\IFactory as IModuleFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\Queries\IFactory as IQueriesFactory;
use Src\Modules\Auth\Infrastructure\Queries\Factory as QueriesFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\Storage\IFactory as IStorageFactory;
use Src\Modules\Auth\Infrastructure\Storage\Factory as StorageFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\PersistLayer\IFactory as IPersistLayerFactory;
use Src\Modules\Auth\Infrastructure\PersistLayer\Factory as PersistLayerFactory;

class Factory implements IFactory {

    private IModuleFactory $moduleFactory;

    protected ?IPersistLayerFactory $persistLayerFactory = null;

    protected ?IQueriesFactory $queriesFactory = null;

    protected ?IStorageFactory $storageFactory = null;

    public function setModuleFactory(IModuleFactory $factory): void
    {
        $this->moduleFactory = $factory;
    }

    public function getModuleFactory(): IModuleFactory
    {
        return $this->moduleFactory;
    }

    public function getPersistLayerFactory(): IPersistLayerFactory
    {
        if($this->persistLayerFactory === null){
            $this->persistLayerFactory = new PersistLayerFactory();
            $this->persistLayerFactory->setInfrastructureFactory($this);
        }
        return $this->persistLayerFactory;
    }

    public function getQueriesFactory(): IQueriesFactory
    {
        if($this->queriesFactory === null){
            $this->queriesFactory = new QueriesFactory();
            $this->queriesFactory->setInfrastructureFactory($this);
        }
        return $this->queriesFactory;
    }

    public function getStorageFactory(): IStorageFactory
    {
        if($this->storageFactory === null){
            $this->storageFactory = new StorageFactory();
            $this->storageFactory->setInfrastructureFactory($this);
        }
        return $this->storageFactory;
    }
    
    

}