/**
 * @desc 分页查询物料列表
 */
import { defaultSuccess, defaultError, http } from '@/plugins/axios';
import type { AxiosResponse } from 'axios';
import type { IPage } from '@/api/api';
export interface Params {
  /** 页码 */
  page?: number;
  /** 页面大小 */
  size?: number;
  /** 类型 */
  type?: number;
  /** 搜索关键词 */
  key?: string;
}

export default async function (
  params: Params,
  success: (data: IPage<material.Material>) => void = defaultSuccess,
  fail: (error: { code: string; error?: string }) => void = defaultError,
): Promise<void> {
  return http({
    method: 'get',
    url: `/materials`,

    params,
  })
    .then((data: AxiosResponse<IPage<material.Material>, unknown>) => {
      success(data.data);
    })
    .catch((error: { code: string; error?: string }) => fail(error));
}
