import useSVGConversationStore from "@/stores/svgConversation";
import { SVGConversationItem } from "@/types/svgConversation";
import { realApi } from "@/utils/request.ts";

/**
 * 生成SVG图片
 * @param {Object} data - 请求体数据
 * @param {string} data.text - 待发送的文本关键词
 * @param {string} data.conversationId - 待发送的会话ID；如果为空，则创建新对话
 * @param {string} data.width - 响应的图片宽度
 * @param {string} data.height - 响应的图片高度
 * @param {File} data.file - 需要修改的上传的文件
 * @param {string} data.type - 图片类型
 */
export function createSVG(data: {
  text: string;
  conversationId?: string;
  width: string;
  height: string;
  file: File;
  type: string;
}) {
  return realApi.post({
    url: "/svg/create",
    data,
  });
}

/**
 * 查询历史会话
 */
export function getSVGConversations(): Promise<SVGConversationItem[]> {
  return realApi.get({
    url: "/svg/history/messages",
  });
}

/**
 * 根据当前会话查看对话记录
 */
export function getSVGConversationById(conversationId: string) {
  return realApi.get({
    url: "/svg/getScholarSvgList",
    params: { conversationId },
  });
}

/**
 * 删除会话
 */
export function deleteSVGConversation(conversationsId: string) {
  return realApi.del({
    url: `/svg/deleteScholarSvg?conversationsId=${conversationsId}`,
  });
}

/**
 * 终止会话
 */
export function stopSVGConversation(conversationsId: string) {
  return realApi.post({
    url: "/svg/stop",
    params: { conversationsId },
  });
}

/**
 * 修改标题
 */
export function updateSVGTitle(data: { messageId: string; message: string }) {
  const { message, messageId } = data;
  return realApi.put({
    url: `/api/createSVG/updatePictureDialogue?messageId=${messageId}&message=${message}`,
    params: data,
  });
}

// 数据部分的接口
interface CreateSVGData {
  id: number;
  conversationsId: string;
  message: string;
  sentAt: string | null;
  number: number;
  pictureDialogueItemList: PictureDialogueItem[];
  taskId: string;
}

// 图片对话项的接口
export interface PictureDialogueItem {
  id: number;
  pictureDialogueId: number;
  SVGsId: number;
  url: string;
  taskId: string | null;
}
