import {request} from "@@/exports";
import {CommonListResponse, CommonResponse} from "@/types/common";
import {ImageItem} from "@/pages/gallery/typings";
// 查询storyItem图片列表
export async function queryStoryItemImages(itemId: string): Promise<{ data: string[] }> {
  return request(`/story/item/images/${itemId}`, {
    method: 'GET',
  });
}
// 获取图片
export async function fetchImage(imageInstanceId: string): Promise<any> {
  return request(`/file/image/${imageInstanceId}`, {
    method: 'GET',
    responseType: 'blob',
    getResponse: true,
  });
}
export async function fetchImageLowRes(imageInstanceId: string): Promise<any> {
  return request(`/file/image-low-res/${imageInstanceId}`, {
    method: 'GET',
    responseType: 'blob',
    getResponse: true,
  });
}
export async function getImagesList(
  params: {
    // query
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<CommonResponse<CommonListResponse<ImageItem>>>('/file/image/list', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

export async function deleteImage(params: { instanceId: string }) {
  return request<CommonResponse<any>>(`/file/image/${params.instanceId}`, {
    method: 'DELETE',
    params: {
      ...params,
    },
  });
}
export async function uploadImage(params: FormData) {
  return request<CommonResponse<any>>('/file/upload-image', {
    method: 'POST',
    data: params,
  });
}
