import request from '@/config/axios'

// ERP 组装拆卸单 VO
export interface AssemblyDisassemblyVO {
  id: number // 编号
  no: string // 单号
  type: number // 类型：10-组装单；20-拆卸单
  bizTime: Date // 组装/拆卸时间
  mainProductId: number // 主产品编号
  mainWarehouseId: number // 主产品仓库编号
  mainCount: number // 主产品数量
  totalSubCount: number // 合计子产品数量
  totalPrice: number // 合计金额
  status: number // 状态
  remark: string // 备注
  items?: AssemblyDisassemblyItemVO[] // 子产品明细
}

// ERP 组装拆卸单项 VO
export interface AssemblyDisassemblyItemVO {
  id?: number // 明细编号
  warehouseId: number // 仓库编号
  productId: number // 产品编号
  productPrice?: number // 产品单价
  count: number // 产品数量
  remark?: string // 备注
}

// 组装拆卸单类型枚举
export const AssemblyDisassemblyType = {
  ASSEMBLY: 10, // 组装单
  DISASSEMBLY: 20 // 拆卸单
}

// ERP 组装拆卸单 API
export const AssemblyDisassemblyApi = {
  // 查询组装拆卸单分页
  getAssemblyDisassemblyPage: async (params: any) => {
    return await request.get({ url: `/erp/assembly-disassembly/page`, params })
  },

  // 查询组装拆卸单详情
  getAssemblyDisassembly: async (id: number) => {
    return await request.get({ url: `/erp/assembly-disassembly/get?id=` + id })
  },

  // 新增组装拆卸单
  createAssemblyDisassembly: async (data: AssemblyDisassemblyVO) => {
    return await request.post({ url: `/erp/assembly-disassembly/create`, data })
  },

  // 修改组装拆卸单
  updateAssemblyDisassembly: async (data: AssemblyDisassemblyVO) => {
    return await request.put({ url: `/erp/assembly-disassembly/update`, data })
  },

  // 更新组装拆卸单的状态
  updateAssemblyDisassemblyStatus: async (id: number, status: number) => {
    return await request.put({
      url: `/erp/assembly-disassembly/update-status`,
      params: {
        id,
        status
      }
    })
  },

  // 删除组装拆卸单
  deleteAssemblyDisassembly: async (ids: number[]) => {
    return await request.delete({
      url: `/erp/assembly-disassembly/delete`,
      params: {
        ids: ids.join(',')
      }
    })
  },

  // 导出组装拆卸单 Excel
  exportAssemblyDisassembly: async (params) => {
    return await request.download({ url: `/erp/assembly-disassembly/export-excel`, params })
  }
}
