<?php

namespace Opencart\Extension\Alsendo\DTO\Entity;

require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/OrderDetailsEntityFactoryInterface.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/Apaczka/ApaczkaOrderDetailsEntityFactory.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/Ecolet/EcoletOrderDetailsEntityFactory.php');
require_once(DIR_EXTENSION . 'alsendo/src/DTO/Entity/Zaslat/ZaslatOrderDetailsEntityFactory.php');

use Opencart\Extension\Alsendo\DTO\Entity\Apaczka\ApaczkaOrderDetailsEntityFactory;
use Opencart\Extension\Alsendo\DTO\Entity\Ecolet\EcoletOrderDetailsEntityFactory;
use Opencart\Extension\Alsendo\DTO\Entity\Zaslat\ZaslatOrderDetailsEntityFactory;

class RegionOrderDetailsEntityFactory
{
    private const REGION_TO_PROVIDER = [
        'poland' => 'apaczka',
        'romania' => 'ecolet',
        'czechia' => 'zaslat',
    ];

    private array $factories = [];

    public function __construct()
    {
        $this->factories['apaczka'] = new ApaczkaOrderDetailsEntityFactory();
        $this->factories['ecolet'] = new EcoletOrderDetailsEntityFactory();
        $this->factories['zaslat'] = new ZaslatOrderDetailsEntityFactory();
    }

    public function getFactoryForRegionCode(string $regionCode): OrderDetailsEntityFactoryInterface
    {
        $provider = self::REGION_TO_PROVIDER[strtolower($regionCode)] ?? 'apaczka';
        return $this->factories[$provider];
    }

    public static function getProviderFromRegionCode(string $regionCode): string
    {
        return self::REGION_TO_PROVIDER[strtolower($regionCode)] ?? 'apaczka';
    }
}
