import request from '@/config/axios'

/**
 * 工序状态枚举
 * status: 0-未开始, 1-进行中, 2-已完成, 3-已暂停
 */
export enum OperationStatus {
  PENDING = 0, // 未开始
  IN_PROGRESS = 1, // 进行中
  COMPLETED = 2, // 已完成
  PAUSED = 3 // 已暂停
}

/**
 * 获取工单工序列表
 */
export function YVHgetWorkOrderOperationList(orderId: number) {
  return request.get({ url: '/mes/production-order-operation/list', params: { orderId } })
}

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

/**
 * 开始工序
 */
export function YVHstartOperation(data: {
  id: number
  workerId: number
  workerName: string
  equipmentId?: number
  equipmentName?: string
  inputQuantity: number
  remark?: string
}) {
  return request.post({ url: '/mes/production-order-operation/start', data })
}

/**
 * 完成工序
 */
export function YVHcompleteOperation(data: {
  id: number
  executionId: number
  outputQuantity: number
  qualifiedQuantity: number
  unqualifiedQuantity: number
  remark?: string
}) {
  return request.post({ url: '/mes/production-order-operation/complete', data })
}

/**
 * 暂停工序
 */
export function YVHpauseOperation(data: { id: number; executionId: number; remark?: string }) {
  return request.post({ url: '/mes/production-order-operation/pause', data })
}

/**
 * 恢复工序
 */
export function YVHresumeOperation(data: {
  id: number
  workerId: number
  workerName: string
  equipmentId?: number
  equipmentName?: string
  remark?: string
}) {
  return request.post({ url: '/mes/production-order-operation/resume', data })
}

/**
 * 获取工序进度统计
 */
export function YVHgetOperationProgress(orderId: number) {
  return request.get({ url: '/mes/production-order-operation/progress', params: { orderId } })
}

/** 记录工序进度 */
export const YVHrecordOperationProgress = (data: {
  executionId: number
  processData?: string
  remark?: string
}) => {
  return request.post({ url: '/mes/production-order-operation/record-progress', data })
}

// 获取工序进度记录列表
export function YVHgetOperationProgressList(executionId: number) {
  return request.get({
    url: '/mes/production-order-operation/progress-list',
    params: { executionId }
  })
}

/**
 * 编辑工序进度记录
 */
export function YVHupdateOperationProgress(data: {
  id: number
  processData?: string
  remark?: string
}) {
  return request.put({ url: '/mes/production-order-operation/update-progress', data })
}
