/**
 * @file agent_message.c
 * @brief AI Agent 发送消息构建实现
 */

#include "protocol/agent_message.h"
#include <stdio.h>
#include <string.h>

int agent_msg_create_break(char *buf, size_t buf_size)
{
    if (!buf || buf_size < 5) {
        return -1;
    }
    int n = snprintf(buf, buf_size, "[B]:");
    return n;
}

int agent_msg_create_text(const char *text, char *buf, size_t buf_size)
{
    if (!text || !buf || buf_size < 5) {
        return -1;
    }
    int n = snprintf(buf, buf_size, "[T]:%s", text);
    return (n > 0 && (size_t)n < buf_size) ? n : -1;
}

int agent_msg_create_tts(const char *text, char *buf, size_t buf_size)
{
    if (!text || !buf || buf_size < 7) {
        return -1;
    }
    int n = snprintf(buf, buf_size, "[TTS]:%s", text);
    return (n > 0 && (size_t)n < buf_size) ? n : -1;
}

int agent_msg_create_fc_result(const char *session_id, const char *result,
                                char *buf, size_t buf_size)
{
    if (!session_id || !result || !buf) {
        return -1;
    }
    /* 格式: [F]:[RESULT]:{"session_id":"xxx","result":"xxx"} */
    int n = snprintf(buf, buf_size,
                     "[F]:[RESULT]:{\"session_id\":\"%s\",\"result\":%s}",
                     session_id, result);
    return (n > 0 && (size_t)n < buf_size) ? n : -1;
}

int agent_msg_create_switch_voice(const char *voice_id, char *buf, size_t buf_size)
{
    if (!voice_id || !buf) {
        return -1;
    }
    /* 格式: [E]:[CMD]:SWITCH_VOICE:voice_id */
    int n = snprintf(buf, buf_size, "[E]:[CMD]:SWITCH_VOICE:%s", voice_id);
    return (n > 0 && (size_t)n < buf_size) ? n : -1;
}
