/**
 * @description 对话相关API
 * @author yslg
 * @since 2025-10-15
 */

import { api } from '@/apis/index';
import type { AiConversation, ResultDomain } from '@/types';

/**
 * 对话API服务
 */
export const conversationApi = {
  /**
   * 获取用户对话列表
   * @param userID 用户ID
   * @returns Promise<ResultDomain<AiConversation>>
   */
  async getConversationList(userID: string): Promise<ResultDomain<AiConversation>> {
    const response = await api.get<AiConversation>('/ai/conversation/list', { userID });
    return response.data;
  },

  /**
   * 创建对话
   * @param conversation 对话数据
   * @returns Promise<ResultDomain<AiConversation>>
   */
  async createConversation(conversation: AiConversation): Promise<ResultDomain<AiConversation>> {
    const response = await api.post<AiConversation>('/ai/conversation/create', conversation);
    return response.data;
  },

  /**
   * 删除对话
   * @param conversationID 对话ID
   * @returns Promise<ResultDomain<boolean>>
   */
  async deleteConversation(conversationID: string): Promise<ResultDomain<boolean>> {
    const response = await api.delete<boolean>(`/ai/conversation/${conversationID}`);
    return response.data;
  },

  /**
   * 清空对话记录
   * @param conversationID 对话ID
   * @returns Promise<ResultDomain<boolean>>
   */
  async clearConversation(conversationID: string): Promise<ResultDomain<boolean>> {
    const response = await api.post<boolean>(`/ai/conversation/${conversationID}/clear`);
    return response.data;
  }
};
