import axiosInstance from '../../utils/axios';

export interface MaterialsQuery {
  pageNo?: number;
  pageSize?: number;
  current?: number;
  size?: number;
  materialsName?: string;
  materialsTypeId?: number;
  cabinetId?: number;
  loanState?: number;
  [key: string]: any;
}

export interface MaterialsVO {
  materialsId?: number;
  materialsName: string;
  materialsTypeId: number;
  materialsIcon?: string;
  materialsPicture?: string;
  loanState?: number;
  loanUserId?: string;
  loanTime?: Date | string;
  restitutionToId?: string;
  restitutionUserId?: string;
  restitutionTime?: Date | string;
  remark?: string;
  [key: string]: any;
}

export interface MaterialsBindingVO {
  materialsId: number;
  cabinetId: number;
}

export interface MaterialsLoanVO {
  materialsId: number;
  loanState: number;
  loanUserId?: string;
  restitutionToId?: string;
  restitutionUserId?: string;
}

export const materialInformationApi = {
  listMaterials: (params: MaterialsQuery) =>
    axiosInstance.get('/iscs/materials/getMaterialsPage', { params }),
  getMaterialsInfo: (id: number) =>
    axiosInstance.get('/iscs/materials/selectMaterialsById', { params: { id } }),
  addMaterials: (data: MaterialsVO) => axiosInstance.post('/iscs/materials/insertMaterials', data),
  updateMaterials: (data: MaterialsVO) => axiosInstance.put('/iscs/materials/updateMaterials', data),
  deleteMaterials: (ids: number | string) =>
    axiosInstance.delete('/iscs/materials/deleteMaterialsList', { params: { ids } }),
  getMaterialsCabinets: (params: MaterialsQuery) =>
    axiosInstance.get('/iscs/materials-cabinet/getMaterialsCabinetPage', { params }),
  updateMaterialsBinding: (data: MaterialsBindingVO) =>
    axiosInstance.post('/iscs/materials/updateMaterialsBinding', data),
  updateMaterialsLoan: (data: MaterialsLoanVO[]) =>
    axiosInstance.post('/iscs/materials/updateIsMaterialById', { list: data }),
  getExMaterials: (params: MaterialsQuery) =>
    axiosInstance.get('/iscs/materials/getExMaterials', { params }),
  getExMaterialType: (params: { materialsId: number }) =>
    axiosInstance.get('/iscs/hardware/material-api/selectExMaterialTypeById', { params }),
};
