import { post } from './request';
import { ApiResponse } from './common';

// 创建剧本项目的数据类型
export interface CreateScriptProjectRequest {
  title?: string;
  script_author?: string;
  characters?: Array<{
    name?: string;
    desc?: string;
  }>;
  summary?: string;
  project_type?: number;
  status?: number;
  cate_tags?: string[];
  creator_name?: string;
  mode?: number;
  resolution?: number;
}

// 剧本项目数据类型
export interface ScriptProject {
  id: number;
  title: string;
  script_author: string;
  characters: Array<{
    name: string;
    desc: string;
  }>;
  summary: string;
  project_type: number;
  status: number;
  cate_tags: string[];
  creator_name: string;
  updated_at?: string;
  created_at?: string;
  mode: number;
  resolution: number;
}

// 获取剧本项目列表请求数据类型
export interface GetScriptProjectListRequest {
  page: number; // 页码 从1开始
  per_page: number; // 每页条数 默认10条
  sort_by: string; // 排序字段 默认update_time
  sort_order: string; // 排序顺序 默认desc
  project_type: number; // 项目类型 默认1
}
// 获取剧本项目列表响应数据类型
export interface ScriptProjectList {
  total: number;
  items: ScriptProject[];
}

// 修改剧本项目请求数据类型
export interface UpdateScriptProjectRequest {
  id: number;
  title?: string;
  script_author?: string;
  characters?: Array<{
    name?: string;
    desc?: string;
  }>;
  summary?: string;
  status?: number;
}

// 删除剧本项目请求数据类型
export interface DeleteScriptProjectRequest {
  id: number;
}

// 创建剧本项目
export const createScriptProject = async (data: CreateScriptProjectRequest): Promise<ApiResponse<ScriptProject>> => {
  return post<ApiResponse<ScriptProject>>('/script_project/create', data);
};

// 获取剧本项目列表
export const getScriptProjectList = async (data: GetScriptProjectListRequest): Promise<ApiResponse<ScriptProjectList>> => {
  return post<ApiResponse<ScriptProjectList>>('/script_project/page', data);
};

// 修改剧本项目
export const updateScriptProject = async (data: UpdateScriptProjectRequest): Promise<ApiResponse<ScriptProject>> => {
  return post<ApiResponse<ScriptProject>>('/script_project/update', data);
};

// 删除剧本项目
export const deleteScriptProject = async (data: DeleteScriptProjectRequest): Promise<ApiResponse<ScriptProject>> => {
  return post<ApiResponse<ScriptProject>>('/script_project/delete', data);
};

// 获取剧本项目详情请求数据类型
export interface GetScriptProjectDetailRequest {
  id: number;
}

// 获取剧本项目详情
export const getScriptProjectDetail = async (data: GetScriptProjectDetailRequest): Promise<ApiResponse<ScriptProject>> => {
  return post<ApiResponse<ScriptProject>>('/script_project/detail', data);
};