package com.easyagents.core.test.model.client;

import com.easyagents.core.message.UserMessage;
import com.easyagents.core.model.chat.ChatConfig;
import com.easyagents.core.model.client.OpenAIChatMessageSerializer;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;
import java.util.Map;

/**
 * OpenAI-compatible 多模态消息序列化测试。
 */
public class OpenAIChatMessageSerializerTest {

    /**
     * 验证 Data URI 会写入标准的 image_url.url 字段。
     */
    @Test
    public void shouldSerializeImageDataUriIntoImageUrlField() {
        String dataUri = "data:image/png;base64,AQID";
        UserMessage message = new UserMessage("识别图片");
        message.addImageUrl(dataUri);

        List<Map<String, Object>> messages = new OpenAIChatMessageSerializer()
                .serializeMessages(List.of(message), new ChatConfig());

        Assert.assertNotNull(messages);
        List<?> content = (List<?>) messages.get(0).get("content");
        Map<?, ?> imageContent = (Map<?, ?>) content.get(1);
        Map<?, ?> imageUrl = (Map<?, ?>) imageContent.get("image_url");
        Assert.assertEquals("image_url", imageContent.get("type"));
        Assert.assertEquals(dataUri, imageUrl.get("url"));
    }
}
