import request from '@/config/axios'

/**
 * @author:huangtianci
 * 工单分页查询
 */
export function YVHgetWorkOrderPage(params: any) {
  return request.get({ url: '/mes/production-order/page', params })
}

/**
 * @author:huangtianci
 * 获取工单详情
 */
export function YVHgetWorkOrder(id: number) {
  return request.get({ url: '/mes/production-order/get', params: { id } })
}

/**
 * @author:huangtianci
 * 获取工单精简信息列表
 */
export function YVHgetWorkOrderSimpleList(params?: { status?: number }) {
  return request.get({ url: '/mes/production-order/list-all-simple', params })
}

/**
 * @author:huangtianci
 * 创建工单
 */
export function YVHcreateWorkOrder(data: any) {
  return request.post({ url: '/mes/production-order/create', data })
}

/**
 * @author:huangtianci
 * 更新工单
 */
export function YVHupdateWorkOrder(data: any) {
  return request.put({ url: '/mes/production-order/update', data })
}

/**
 * @author:huangtianci
 * 删除工单
 */
export function YVHdeleteWorkOrder(id: number) {
  return request.delete({ url: '/mes/production-order/delete', params: { id } })
}

/**
 * @author:huangtianci
 * 提交工单审核
 */
export function YVHsubmitWorkOrder(data: { id: number; remark?: string }) {
  return request.post({ url: '/mes/production-order/submit', data })
}

/**
 * @author:huangtianci
 * 审核通过工单
 */
export function YVHapproveWorkOrder(data: { id: number; remark?: string }) {
  return request.post({ url: '/mes/production-order/approve', data })
}

/**
 * @author:huangtianci
 * 拒绝工单
 */
export function YVHrejectWorkOrder(data: { id: number; remark?: string }) {
  return request.post({ url: '/mes/production-order/reject', data })
}

/**
 * @author:huangtianci
 * 开始生产工单
 */
export function YVHstartWorkOrder(data: { id: number; remark?: string }) {
  return request.post({ url: '/mes/production-order/start', data })
}

/**
 * @author:huangtianci
 * 完成工单
 */
export function YVHcompleteWorkOrder(data: { id: number; producedQuantity: number; remark?: string }) {
  return request.post({ url: '/mes/production-order/complete', data })
}

/**
 * @author:huangtianci
 * 关闭工单
 */
export function YVHcloseWorkOrder(data: { id: number; remark?: string }) {
  return request.post({ url: '/mes/production-order/close', data })
}

/**
 * @author:huangtianci
 * 取消工单
 */
export function YVHcancelWorkOrder(data: { id: number; remark?: string }) {
  return request.post({ url: '/mes/production-order/cancel', data })
}

/**
 * 获取产品在时间范围内的原料消耗汇总
 * GET /mes/production-order/report
 */
export function YVHgetProductionReport(params: {
  productId: number | string
  startTime: string
  endTime: string
}) {
  return request.get({ url: '/mes/production-order/report', params })
}

/**
 * 汇总指定产品在时间范围内的实际生产数量
 * GET /mes/production-order/report/sum-produced-quantity
 * @deprecated 请使用 YVHgetProductionReport 替代
 */
export function YVHsumProducedQuantity(params: {
  productId: number | string
  startTime: string
  endTime: string
}) {
  return request.get({ url: '/mes/production-order/report/sum-produced-quantity', params })
}
