import type { JsonObject } from '../../../types/json.js'
export function buildIndustrySuccessResponse(data: unknown = null) {
  return {
    result: 1,
    error_msg: '',
    data: data || {},
  }
}

export function buildIndustryErrorResponse(result: number, errorMsg: string) {
  return {
    result,
    error_msg: errorMsg || '系统异常',
    data: null as null,
  }
}

export function buildIndustryEticketItem(eticket: {
  id: string
  code?: string
  status?: string
  num?: number
  validStartTime?: number
  validEndTime?: number
  consumeDetails?: JsonObject[]
  eticketType?: string
}) {
  const item: JsonObject = {
    id: eticket.id,
    status: eticket.status || 'UNUSED',
    num: eticket.num || 1,
    validStartTime: eticket.validStartTime || 0,
    validEndTime: eticket.validEndTime || 0,
  }

  if (eticket.code) {
    item.code = eticket.code
  }

  if (eticket.consumeDetails && eticket.consumeDetails.length > 0) {
    item.eticketConsumeDetails = eticket.consumeDetails.map((detail) => ({
      serialNum: detail.serialNum || '',
      consumeType: detail.consumeType || '',
      consumeTime: detail.consumeTime || 0,
      appointmentTime: detail.appointmentTime,
      storeName: detail.storeName,
      storeAddress: detail.storeAddress,
      expressCode: detail.expressCode,
      expressName: detail.expressName,
      expressNo: detail.expressNo,
      reason: detail.reason,
      ext: detail.ext,
    }))
  }

  if (eticket.eticketType) {
    item.eticketType = eticket.eticketType
  }

  return item
}

export function buildIndustrySendCodeData(data: {
  oid: string
  sendType: string
  sendNum: number
  etickets: JsonObject[]
}) {
  return {
    oid: data.oid,
    sendType: data.sendType,
    sendNum: data.sendNum,
    etickets: data.etickets,
  }
}

export function buildIndustryQueryCodeData(data: {
  oid: string
  sendType: string
  sendNum: number
  etickets: JsonObject[]
}) {
  return {
    oid: data.oid,
    sendType: data.sendType,
    sendNum: data.sendNum,
    etickets: data.etickets,
  }
}
