package com.erp.ai.client;

import com.erp.ai.exception.LlmClientException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 모델 이름으로 적절한 LlmClient 구현체 라우팅.
 * architecture §9.3.
 */
@Component
@RequiredArgsConstructor
public class LlmClientFactory {

    private final List<LlmClient> clients;

    public LlmClient pick(String model) {
        if (model == null || model.isBlank()) {
            throw new LlmClientException("모델이 지정되지 않았습니다.");
        }
        return clients.stream()
                .filter(c -> c.supports(model))
                .findFirst()
                .orElseThrow(() -> new LlmClientException("지원하지 않는 모델: " + model));
    }

    public List<LlmClient> all() {
        return clients;
    }
}
