import request from '@/utils/request';
import type { ApiResult } from '@/api/index';

/**
 * AI聊天消息接口
 */
export interface AiChatMessage {
  query: string;
  user?: string;
  responseMode?: string;
  conversationId?: string;
  type?: string;
  requestType?: number;
  aiToken?: string;
}

/**
 * AI聊天响应接口
 */
export interface AiChatResponse {
  answer: string;
  taskId: string;
}

/**
 * 发送AI聊天消息
 */
export async function sendAiMessage(data: AiChatMessage) {
  const res = await request.post<ApiResult<string>>(
    '/chat/message',
    data
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 停止AI聊天
 */
export async function stopAiMessage(data: { taskId: string; type?: string }) {
  const res = await request.post<ApiResult<string>>(
    '/chat/messageStop',
    data
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}


