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

export interface CheckRecordQuery {
  pageNo?: number;
  pageSize?: number;
  current?: number;
  size?: number;
  /** 检查计划维度筛选（若后端支持） */
  planId?: number;
  materialsCheckPlanId?: number;
  planName?: string;
  cabinetId?: number;
  materialsId?: number;
  materialsName?: string;
  materialsTypeId?: number;
  materialsRfid?: string;
  /** 检查结果（旧版 dict CHECKS_STATUS） */
  status?: number | string;
  /** 异常原因（旧版 dict EXCEPTIONS_STATUS） */
  reason?: number | string;
  startTime?: string;
  endTime?: string;
  checkStatus?: number;
  checkTime?: Date[] | string[];
  [key: string]: any;
}

export interface CheckRecordVO {
  recordId?: number;
  cabinetId: number;
  materialsId: number;
  checkStatus: number;
  checkTime?: Date | string;
  checkResult: string;
  remark?: string;
  [key: string]: any;
}

export const materialCheckRecordApi = {
  listCheckRecord: (params: CheckRecordQuery) =>
    axiosInstance.get('/iscs/materials-check-record/getMaterialsCheckRecordPage', { params }),
  getCheckRecordInfo: (id: number) =>
    axiosInstance.get('/iscs/materials-check-record/selectMaterialsCheckRecordById', { params: { id } }),
  addCheckRecord: (data: CheckRecordVO) =>
    axiosInstance.post('/iscs/materials-check-record/insertMaterialsCheckRecord', data),
  updateCheckRecord: (data: CheckRecordVO) =>
    axiosInstance.post('/iscs/materials-check-record/updateMaterialsCheckRecord', data),
  deleteCheckRecord: (ids: number) =>
    axiosInstance.post(`/iscs/materials-check-record/deleteMaterialsCheckRecordList?ids=${ids}`),
  exportCheckRecord: (params: Record<string, any>) =>
    axiosInstance.get('/iscs/materials-check-record/exportMaterialsCheckRecordExcel', {
      params,
      responseType: 'blob',
    }),
};
