import type {
  GenerateImageRequest,
  ImageModel,
  PublishImageRequest,
  TaskListRequest,
  TaskListResponse,
  TaskStatusResponse,
} from './types';
import { del, get, post } from '@/utils/request';

export function generateImage(data: GenerateImageRequest) {
  return post<string>('/ai-image/generate', data).json();
}

export function getTaskStatus(taskId: string) {
  return get<TaskStatusResponse>(`/ai-image/task/${taskId}`).json();
}

export function getMyTasks(params: TaskListRequest) {
  return get<TaskListResponse>('/ai-image/my-tasks', params).json();
}

export function getImagePlaza(params: TaskListRequest) {
  return get<TaskListResponse>('/ai-image/plaza', params).json();
}

export function publishImage(data: PublishImageRequest) {
  return post<void>('/ai-image/publish', data).json();
}

export function getImageModels() {
  return post<ImageModel[]>('/ai-image/model').json();
}
export function deleteMyTasks(taskIds: string[]) {
  const query = taskIds.map(id => `ids=${encodeURIComponent(id)}`).join('&');
  const url = `/ai-image/my-tasks${query ? `?${query}` : ''}`;
  return del<void>(url).json();
}
