<?php
namespace EasyChat\Library\Crm;

use EasyChat\Library\Http\ExternalHttpClient;

final class CrmProviderRegistry {
    private $registry;
    private $http;

    public function __construct($registry, ?ExternalHttpClient $http = null) {
        $this->registry = $registry;
        $this->http = $http;
    }

    public function get(string $provider): CrmProviderInterface {
        $provider = strtolower(trim($provider));
        if ($provider === 'bitrix24') {
            return new Bitrix24Provider($this->registry, $this->http);
        }
        if ($provider === 'amocrm') {
            return new AmoCrmProvider($this->registry, $this->http);
        }
        if ($provider === 'retailcrm') {
            return new RetailCrmProvider($this->registry, $this->http);
        }
        throw new \InvalidArgumentException('crm_provider_unsupported');
    }

    public function codes(): array { return array('bitrix24', 'amocrm', 'retailcrm'); }
}
