import { requestClient } from '#/api/request';

const prefix = 'file-gallery/';

export interface FileGalleryItem {
  id: number;
  url: string;
  file_name?: string;
  file_size: number;
  file_size_text: string;
  type?: number;
  type_text?: string;
  type_icon?: string;
  created_at?: string;
  original_name?: string;
  object_key?: string;
  source?: number;
}

export interface FileTypeItem {
  id: number;
  name: string;
  icon?: string;
  value: number;
  suffix: string;
  sort: number;
}

export interface FileGalleryDetail extends FileGalleryItem {
  source_text?: string;
  updated_at?: string;
}

export async function getFileGalleryList(params?: {
  page?: number;
  page_size?: number;
  pid?: number;
  type?: number;
  keyword?: string;
}) {
  return requestClient.get<{
    items: FileGalleryItem[];
    total: number;
    page: number;
    page_size: number;
  }>(`${prefix}list`, { params });
}

export async function getFileGalleryDetail(id: number) {
  return requestClient.get<FileGalleryDetail>(`${prefix}detail`, { params: { id } });
}

export async function deleteFileGalleryItem(id: number) {
  return requestClient.post<any>(`${prefix}delete`, { id });
}

export async function renameFileGalleryItem(id: number, file_name: string) {
  return requestClient.post<any>(`${prefix}rename`, { id, file_name });
}

export async function moveFileGalleryType(id: number, type: number) {
  return requestClient.post<any>(`${prefix}move-type`, { id, type });
}

export async function batchArchiveFiles() {
  return requestClient.post<{
    reclassified: number;
    file_name_filled: number;
  }>(`${prefix}batch-archive`);
}

export async function getFileTypes() {
  return requestClient.get<FileTypeItem[]>(`${prefix}file-types`);
}

export async function syncFileGalleryFromOss() {
  return requestClient.post<{ synced: number; skipped: number; scanned: number }>(`${prefix}sync-oss`);
}
