import { IListResponse_DTO } from "@shared/contexts";
import { AxiosHeaderValue, ResponseType } from "axios";

export interface IPaginationDataProviderParam {
  pageIndex: number;
  pageSize: number;
}

export interface ISortItemDataProviderParam {
  order: string;
  field: string;
}

export interface IFilterItemDataProviderParam {
  field: string;
  operator?: string;
  value?: string;
}

export interface IGetListDataProviderParams {
  resource: string;
  quickSearchTerm?: string[];
  pagination?: IPaginationDataProviderParam;
  sort?: ISortItemDataProviderParam[];
  filters?: IFilterItemDataProviderParam[];
}

export interface IGetOneDataProviderParams {
  resource: string;
  id: string;
}

export interface ISaveOneDataProviderParams<T> {
  resource: string;
  data: T;
  id: string;
}

export interface ICreateOneDataProviderParams<T> {
  resource: string;
  data: T;
}

export interface IUpdateOneDataProviderParams<T> {
  resource: string;
  data: T;
  id: string;
}

export interface IRemoveOneDataProviderParams {
  resource: string;
  id: string;
}

export interface IDownloadPDFDataProviderParams {
  url: string;
  config?: {
    [key: string]: unknown;
  };
}

export interface IDownloadPDFDataProviderResponse {
  filename: string;
  filedata: Blob;
}

export interface IUploadFileDataProviderParam {
  path: string;
  //resource: string;
  //id: string;
  file: File;
  key: string;
  onUploadProgress?: any;
}

export interface ICustomDataProviderParam {
  url?: string;
  path?: string;
  method: "get" | "delete" | "head" | "options" | "post" | "put" | "patch";
  signal?: AbortSignal;
  responseType?: ResponseType;
  headers?: {
    [key: string]: AxiosHeaderValue;
  };
  [key: string]: unknown;
}

export interface IDataSource {
  name: () => string;
  getList: <R>(params: IGetListDataProviderParams) => Promise<IListResponse_DTO<R>>;
  getOne: <R>(params: IGetOneDataProviderParams) => Promise<R>;
  //saveOne: <P, R>(params: ISaveOneDataProviderParams<P>) => Promise<R>;
  createOne: <P, R>(params: ICreateOneDataProviderParams<P>) => Promise<R>;
  updateOne: <P, R>(params: IUpdateOneDataProviderParams<P>) => Promise<R>;
  removeOne: (params: IRemoveOneDataProviderParams) => Promise<void>;
  downloadPDF: (
    params: IDownloadPDFDataProviderParams
  ) => Promise<IDownloadPDFDataProviderResponse>;
  uploadFile: <R>(params: IUploadFileDataProviderParam) => Promise<R>;
  custom: <R>(params: ICustomDataProviderParam) => Promise<R>;

  getApiUrl: () => string;
  getApiAuthorization: () => string;

  //create: () => any;
  //createMany: () => any;
  //removeMany: () => any;
  //getMany: () => any;
  //update: () => any;
  //updateMany: () => any;
  //upload: () => any;
  //custom: () => any;
  //getApiUrl: () => string;
}
