import { ImageConversationMesg } from "@/types/imageConversation";
import { realApi } from "@/utils/request.ts";

/**
 * 生成图片
 */
export function createImage(data: {
  number?: number;
  prompt: string;
  conversationId?: string;
}): Promise<ImageConversationMesg> {
  data.conversationId = data.conversationId ?? ""; // 设置默认值
  data.number = data.number ?? 1; // 设置默认值
  return realApi.post({
    url: "/api/createImage/create",
    data,
  });
}

/**
 * 请求图片url,携带token
 */
export function getImageUrl(url: string) {
  return realApi.get({
    url,
  });
}
/**
 * 查询历史会话
 */
export function getImageConversations() {
  return realApi.get({
    url: "/api/createImage/list",
  });
}

/**
 * 根据当前会话查看对话记录
 */
export function getImageConversationById(
  conversationId: string
): Promise<ImageConversationMesg[]> {
  return realApi.get({
    url: "/api/createImage/getConversationIdByList",
    params: { conversationId },
  });
}

/**
 * 删除会话
 */
export function deleteImageConversation(conversationsId: string) {
  return realApi.del({
    url: `/api/createImage/delete?conversationsId=${conversationsId}`,
  });
}

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

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

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

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