import request from '@/config/axios'

// 物资信息查询参数
export interface MaterialsQuery {
  current: number
  size: number
  materialsName?: string
  materialsTypeId?: number
  cabinetId?: number
  loanState?: number
}

// 物资信息表单对象
export interface MaterialsVO {
  materialsId?: number
  materialsName: string
  materialsTypeId: number
  materialsIcon?: string
  materialsPicture?: string
  loanState: number
  loanUserId?: string
  loanTime?: Date
  restitutionToId?: string
  restitutionUserId?: string
  restitutionTime?: Date
  remark?: string
  createTime?: Date
}

// 物资绑定参数
export interface MaterialsBindingVO {
  materialsId: number
  cabinetId: number
}

// 物资借还参数
export interface MaterialsLoanVO {
  materialsId: number
  loanState: number
  loanUserId?: string
  restitutionToId?: string
  restitutionUserId?: string
}

// 物资更换记录参数
export interface MaterialsChangeVO {
  materialsId: number
  oldCabinetId: number
  newCabinetId: number
  changeReason: string
}

// 物资检查记录参数
export interface MaterialsCheckVO {
  materialsId: number
  checkStatus: number
  checkResult: string
}

// 查询物资信息列表
export const listMaterials = async (params: MaterialsQuery) => {
  return await request.get({ url: '/iscs/materials/getMaterialsPage', params })
}

// 查询物资信息详情
export const getMaterialsInfo = async (id: number) => {
  return await request.get({
    url: '/iscs/materials/selectMaterialsById',
    params: { id: id }
  })
}

// 新增物资信息
export const addMaterials = async (data: MaterialsVO) => {
  return await request.post({ url: '/iscs/materials/insertMaterials', data })
}

// 修改物资信息
export const updateMaterials = async (data: MaterialsVO) => {
  return await request.put({ url: '/iscs/materials/updateMaterials', data })
}

// 删除物资信息
export const deleteMaterials = async (ids: number) => {
  return await request.delete({
    url: '/iscs/materials/deleteMaterialsList?ids='+ids,

  })
}

// 查询物资所属柜
export const getMaterialsCabinets = async (params: MaterialsQuery) => {
  return await request.get({ url: '/iscs/materials-cabinet/getMaterialsCabinetPage', params })
}

// 绑定物资
export const updateMaterialsBinding = async (data: MaterialsBindingVO) => {
  return await request.post({ url: '/iscs/materials/updateMaterialsBinding', data })
}

// 物资借出与归还
export const updateMaterialsLoan = async (data: MaterialsLoanVO[]) => {
  return await request.post({
    url: '/iscs/materials/updateIsMaterialById',
    data: { list: data }
  })
}

// 查询异常还错柜子的物资
export const getExMaterials = async (params: MaterialsQuery) => {
  return await request.get({ url: '/iscs/materials/getExMaterials', params })
}

// 查询异常物资类型
export const getExMaterialType = async (params: { materialsId: number }) => {
  return await request.get({
    url: '/iscs/hardware/material-api/selectExMaterialTypeById',
    params
  })
}



