package com.yaoai.ai.providers.service.impl;

import com.yaoai.ai.core.model.ChatMessage;
import com.yaoai.ai.core.model.ChatRequest;
import com.yaoai.ai.providers.config.ArkProperties;
import com.yaoai.common.exception.BizException;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

class ArkLlmServiceTest {

    @Test
    void shouldFailFastWhenApiKeyIsMissing() {
        ArkLlmService service = new ArkLlmService(buildProperties(""));

        BizException exception = assertThrows(BizException.class, () -> service.chat(buildRequest()));

        assertTrue(exception.getMessage().contains("VOLCENGINE_ARK_API_KEY"));
    }

    @Test
    void shouldFailFastWhenApiKeyUsesPlaceholderValue() {
        ArkLlmService service = new ArkLlmService(buildProperties("your-ark-api-key"));

        BizException exception = assertThrows(BizException.class, () -> service.chat(buildRequest()));

        assertTrue(exception.getMessage().contains("VOLCENGINE_ARK_API_KEY"));
    }

    private static ArkProperties buildProperties(String apiKey) {
        ArkProperties properties = new ArkProperties();
        properties.setApiKey(apiKey);
        properties.setBaseUrl("https://ark.cn-beijing.volces.com/api/v3");
        properties.setTextModel("test-model");
        return properties;
    }

    private static ChatRequest buildRequest() {
        return ChatRequest.builder()
                .messages(List.of(ChatMessage.user("hello")))
                .build();
    }
}
