package com.eactive.testmaster.client.service;

import com.eactive.testmaster.client.dto.ApiRequestDTO;
import org.springframework.stereotype.Service;

@Service
public class ApiClientFactory {

    private final NettyHttpApiClient httpApiClient;
    private final NettyTcpApiClient tcpApiClient;

    public ApiClientFactory(NettyHttpApiClient httpApiClient, NettyTcpApiClient tcpApiClient) {
        this.httpApiClient = httpApiClient;
        this.tcpApiClient = tcpApiClient;
    }

    public ApiClient getClient(ApiRequestDTO request) {
        switch (request.getType().toUpperCase()) {
            case "HTTP":
            case "HTTPFLAT":
                return httpApiClient;
            case "TCP":
                return tcpApiClient;
            default:
                throw new IllegalArgumentException("Unsupported client type: " + request.getType());
        }
    }
}
