package tech.easyflow.ai.invoke.provider;

import org.springframework.stereotype.Component;
import tech.easyflow.ai.invoke.exception.ModelInvokeException;

import java.util.List;

@Component
public class ModelProviderGatewayRegistry {

    private final List<ModelProviderGateway> gateways;

    public ModelProviderGatewayRegistry(List<ModelProviderGateway> gateways) {
        this.gateways = gateways;
    }

    public ModelProviderGateway getGateway(String providerType) {
        return gateways.stream()
                .filter(gateway -> gateway.supports(providerType))
                .findFirst()
                .orElseThrow(() -> ModelInvokeException.badRequest(
                        "当前 providerType 暂不支持统一模型调用: " + providerType,
                        "model",
                        "provider_not_supported"
                ));
    }
}
