import type { BasicFetchResult, BasicPageParams } from '#/api/model';

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

export namespace FileApi {
  export interface PageParams extends BasicPageParams {
    fileName?: string;
    suffix?: string;
    startTime?: string;
    endTime?: string;
  }

  export interface BasicRecordItem {
    path: string;
    directory: string;
    allowSuffix: string;
    folderId: string;
    file?: any;
  }

  export interface RecordItem extends BasicRecordItem {
    id: number;
  }

  export interface ListItem {
    id: number;
    folderId: number;
    url: string;
    fileName: string;
    filePath: string;
    sizeKb: number;
  }

  export type PageResult = BasicFetchResult<RecordItem>;

  export const getPage = (params: PageParams) =>
    requestClient.get<PageResult>('/file/page', { params });

  export const getList = (id: number) =>
    requestClient.get<ListItem[]>('/file/list', {
      params: { id },
    });

  export const upload = (data: BasicRecordItem) =>
    requestClient.post('/file/upload', data);

  export const deleteDetail = (id: number) =>
    requestClient.delete('/file', { data: { id } });
}
