import { defHttp } from '/@/utils/http/axios';

export interface PageData<T> {
  total: number;
  items: T[];
}

enum OrderType {
  ASC = 'ASC',
  DESC = 'DESC',
}

export interface BaseQueryParams {
  pageSize: number;
  page: number;
  orderFiled?: string;
  orderType?: OrderType;
}

export class BaseQueryRequest implements BaseQueryParams {
  orderFiled: string | undefined;
  orderType: OrderType | undefined;
  page: number;
  pageSize: number;

  constructor(page = 1, pageSize = 10) {
    this.page = page;
    this.pageSize = pageSize;
  }

  setOrderFiled(orderFiled: string) {
    this.orderFiled = orderFiled;
  }

  setOrderType(orderType: OrderType) {
    this.orderType = orderType;
  }

  setPage(page: number) {
    this.page = page;
  }

  setPageSize(pageSize: number) {
    this.pageSize = pageSize;
  }
}

export function getPageData<T>(params: BaseQueryParams, url: string): Promise<PageData<T>> {
  return defHttp.get<PageData<T>>({
    params: params,
    url: url,
  });
}
