<?php

namespace Src\Modules\Auth;

use Modules\ModulesProvider;
use Src\Modules\Auth\Interfaces\IFactory;
use Src\Modules\Auth\Interfaces\Application\IFactory as IApplicationFactory;
use Src\Modules\Auth\Application\Factory as ApplicationFactory;
use Src\Modules\Auth\Interfaces\Dto\IFactory as IDtoFactory;
use Src\Modules\Auth\Dto\Factory as DtoFactory;
use Src\Modules\Auth\Interfaces\Infrastructure\IFactory as IInfrastructureFactory;
use Src\Modules\Auth\Infrastructure\Factory as InfrastructureFactory;
use Src\Modules\Auth\Interfaces\Pages\IFactory as IPagesFactory;
use Src\Modules\Auth\Pages\Factory as PagesFactory;
use Src\Modules\Auth\Interfaces\Laravel\IFactory as ILaravelFactory;
use Src\Modules\Auth\Laravel\Factory as LaravelFactory;
use Src\Modules\Auth\Interfaces\IModulesProvider;

class Factory implements IFactory {

    private ?IApplicationFactory $applicationFactory = null;

    private ?IDtoFactory $dtoFactory = null;

    private ?IInfrastructureFactory $infrastructureFactory = null;

    private ?IPagesFactory $pagesFactory = null;

    private ?ILaravelFactory $laravelFactory = null;

    private IModulesProvider $modulesProvider;

    private array $settings = [];

    public function injectModules(IModulesProvider $provider): void
    {
        $this->modulesProvider = $provider;
    }

    public function loadSettings(array $settings): void
    {
        $this->settings = $settings;
    }

    public function getSetting(string $key)
    {
        return $this->settings[$key];
    }
    
    public function getModulesProvider(): IModulesProvider
    {
        return $this->modulesProvider;
    }

    public function getApplicationFactory(): ApplicationFactory
    {
        if($this->applicationFactory === null){
            $this->applicationFactory = new ApplicationFactory();
            $this->applicationFactory->setModuleFactory($this);
        }
        return $this->applicationFactory;
    }

    public function getDtoFactory(): DtoFactory
    {
        if($this->dtoFactory === null){
            $this->dtoFactory = new DtoFactory();
            $this->dtoFactory->setModuleFactory($this);
        }
        return $this->dtoFactory;
    }

    public function getInfrastructureFactory(): InfrastructureFactory
    {
        if($this->infrastructureFactory === null){
            $this->infrastructureFactory = new infrastructureFactory();
            $this->infrastructureFactory->setModuleFactory($this);
        }
        return $this->infrastructureFactory;
    }

    public function getPagesFactory(): PagesFactory
    {
        if($this->pagesFactory === null){
            $this->pagesFactory = new PagesFactory();
            $this->pagesFactory->setModuleFactory($this);
        }
        return $this->pagesFactory;
    }

    public function getLaravelFactory(): LaravelFactory
    {
        if($this->laravelFactory === null){
            $this->laravelFactory = new LaravelFactory();
            $this->laravelFactory->setModuleFactory($this);
        }
        return $this->laravelFactory;
    }

}