package tech.easyflow.ai.service.discovery;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import tech.easyflow.ai.entity.Model;
import tech.easyflow.ai.service.capability.ModelCapabilityCatalog;
import tech.easyflow.ai.service.capability.ModelCapabilityResolver;

/**
 * 远端模型目录元数据和默认值补全测试。
 */
public class RemoteModelMetadataResolverTest {

    /** 待测试元数据解析器。 */
    private RemoteModelMetadataResolver resolver;

    /**
     * 加载真实静态模型目录。
     */
    @Before
    public void setUp() {
        ModelCapabilityCatalog catalog = new ModelCapabilityCatalog(new ObjectMapper());
        resolver = new RemoteModelMetadataResolver(catalog, new ModelCapabilityResolver(catalog));
    }

    /**
     * 验证 BAAI 模型使用目录名称、家族和向量类型。
     */
    @Test
    public void shouldEnrichBaaiEmbeddingModel() {
        RemoteModelDescriptor result = resolver.describe(null, "BAAI/bge-m3", false);

        Assert.assertEquals("BGE-M3", result.getDisplayName());
        Assert.assertEquals("bge", result.getFamily());
        Assert.assertEquals(Model.MODEL_TYPES[1], result.getModelType());
        Assert.assertTrue(result.isAddable());
    }

    /**
     * 验证未知模型使用保守对话默认值。
     */
    @Test
    public void shouldConfigureUnknownModelConservatively() {
        Model model = new Model();

        resolver.configureNewModel(model, "self-hosted", "team/custom-model");

        Assert.assertEquals("team/custom-model", model.getTitle());
        Assert.assertEquals("其他模型", model.getGroupName());
        Assert.assertEquals(Model.MODEL_TYPES[0], model.getModelType());
        Assert.assertNull(model.getSupportTool());
        Assert.assertEquals(Boolean.FALSE, model.getSupportVideo());
    }

    /**
     * 验证已知图片生成模型不会进入当前可添加范围。
     */
    @Test
    public void shouldIdentifyUnsupportedImageGenerationModel() {
        Assert.assertTrue(resolver.isUnsupportedGenerationModel("openai", "gpt-image-1"));
        Assert.assertTrue(resolver.isUnsupportedGenerationModel("openai", "gpt-image-1.5"));
        Assert.assertFalse(resolver.isUnsupportedGenerationModel("openai", "gpt-5"));
    }
}
