namespace Kbx.Shared.Integrations;

public sealed class KbxIntegrationAdapterRegistry(IEnumerable<IKbxIntegrationAdapter> adapters)
    : IKbxIntegrationAdapterRegistry
{
    private readonly IReadOnlyDictionary<string, IKbxIntegrationAdapter> _adapters =
        adapters.ToDictionary(x => x.IntegrationId, StringComparer.Ordinal);

    public IKbxIntegrationAdapter GetRequired(string integrationId)
        => _adapters.TryGetValue(integrationId, out var adapter)
            ? adapter
            : throw new InvalidOperationException($"Integration adapter is not registered: {integrationId}");
}
