import { ApiResponse } from "./common";
import {
  StoryAnalysisTask,
  MovieStoryTaskDetail,
  GeminiTextToImageRequest,
  GeminiTextToImageResponse,
  TextToImageRequest,
  TextToImageResponse,
} from "./DTO/movie_start_dto";
import { get, post } from "./request";
import {
  StoryTemplateEntity,
} from "@/app/service/domain/Entities";

/**
 * 获取故事模板列表
 */
export const getTemplateStoryList = async (page?: number, per_page?: number) => {
  return await post<ApiResponse<{
    total: number;
    items: StoryTemplateEntity[];
    page: number;
    per_page: number;
  }>>("/movie_template/story-template-list",{
    page,
    per_page,
  });
};

/**
 * AI分析图片，生成分析结果
 */
export const AIGenerateImageStory = async (request: {
  image_url: string;
  user_text: string;
}) => {
  return await post<ApiResponse<StoryAnalysisTask>>(
    "/movie_story/generate",
    request
  );
};

/**
 * 获取电影故事任务详情
 * @param taskId - 任务ID
 * @returns Promise<ApiResponse<MovieStoryTaskDetail>>
 */
export const getMovieStoryTask = async (taskId: string) => {
  return await get<ApiResponse<MovieStoryTaskDetail>>(
    `/movie_story/task/${taskId}`
  );
};

/**
 * Gemini文本转图像生成
 * @param request - 文本转图像请求参数
 * @returns Promise<GeminiTextToImageResponse>
 */
export const generateGeminiTextToImage = async (
  request: GeminiTextToImageRequest
): Promise<GeminiTextToImageResponse> => {
  return await post<GeminiTextToImageResponse>(
    "/gemini-text-to-image/generate",
    request
  );
};

/**
 * 文本转图像生成
 * @param request - 文本转图像请求参数
 * @returns Promise<TextToImageResponse>
 */
export const generateTextToImage = async (
  request: TextToImageRequest
): Promise<TextToImageResponse> => {
  return await post<TextToImageResponse>(
    "/text-to-image/draw",
    request
  );
};
