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

export interface ChangeRecordQuery {
  pageNo?: number;
  pageSize?: number;
  current?: number;
  size?: number;
  materialsId?: number;
  /** 从检查记录「查看」带入时筛选（若后端支持） */
  recordId?: number;
  checkRecordId?: number;
  materialsCheckRecordId?: number;
  /** 涉及该柜的更换（若后端支持聚合参数） */
  cabinetId?: number;
  oldCabinetId?: number;
  newCabinetId?: number;
  changeTime?: Date | string;
  /** 与旧版 replacementrecords/index.vue 查询参数一致 */
  materialsTypeId?: number;
  oldMaterialsId?: number | string;
  oldMaterialsRfid?: string;
  newMaterialsId?: number | string;
  newMaterialsRfid?: string;
  changeUserName?: string;
  startTime?: string;
  endTime?: string;
  [key: string]: any;
}

export interface ChangeRecordVO {
  changeId?: number;
  materialsId: number;
  oldCabinetId: number;
  newCabinetId: number;
  changeReason: string;
  changeTime?: Date | string;
  remark?: string;
  [key: string]: any;
}

export const materialReplaceApi = {
  listChangeRecord: (params: ChangeRecordQuery) =>
    axiosInstance.get('/iscs/materials-change-record/getMaterialsChangeRecordPage', { params }),
  getChangeRecordInfo: (id: number) =>
    axiosInstance.get('/iscs/materials-change-record/selectMaterialsChangeRecordById', {
      params: { id },
    }),
  addChangeRecord: (data: ChangeRecordVO) =>
    axiosInstance.post('/iscs/change/insertIsMaterialsChangeRecord', data),
  updateChangeRecord: (data: ChangeRecordVO) =>
    axiosInstance.put('/iscs/materials-change-record/updateMaterialsChangeRecord', data),
  deleteChangeRecord: (ids: number) =>
    axiosInstance.post(`/iscs/materials-change-record/deleteMaterialsChangeRecordList?ids=${ids}`),
};
