import { get, post } from '@/utils/request';
/**
 * 获取智能体配置
 */
export const getOnlineInfo = () => {
  return get(`/v1/cozechat/get-online-info`);
};

/**
 * 获取会话列表
 */
export const getConversationList = (data: { page: number; size: number }) => {
  return get(`/v1/cozechat/get-user-conversations`, data);
};

/**
 * 获取指定会话的消息列表
 */
export const getMessageList = (data: {
  conversationId: string;
  page: number;
  size: number;
}) => {
  return get(`/v1/cozechat/get-user-chat-record`, data);
};

/**
 * 发送消息
 */
export const startChat = (
  data: {
    content: string;
    conversationId: string;
    fileUrl?: string[];
    id?: string;
  },
  signal: AbortSignal,
) => {
  return post(`/v1/cozechat/create-chat-stream`, data, {
    signal: signal,
    headers: {
      Accept: 'text/event-stream',
    },
    responseType: 'stream',
    adapter: 'fetch', // 使用 Fetch 适配器
  });
};

/**
 * 删除会话
 * @param conversationId
 * @returns
 */
export const deleteConversation = (conversationId: string) => {
  return get(`/v1/cozechat/delete-conversation`, { conversationId });
};

/**
 * 中断对话
 * @param data
 * @returns
 */
export const interruptChat = (data: {
  conversationId: string;
  chatId: string;
}) => {
  return post(`/v1/cozechat/interrupt-chat`, data);
};

/**
 * 删除消息
 * @param id
 * @returns
 */
export const deleteMessage = (id: string) => {
  return get(`/v1/cozechat/delete-chat-record`, { id });
};

export const uploadFile = (data: any) => {
  return post('/v1/file_upload/upload_file', data, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};
