import request from '@/utils/request'

export function listWecomShareLinkLogisticsJob(query) {
  return request({
    url: '/jarvis/wecom/shareLinkLogisticsJob/list',
    method: 'get',
    params: query
  })
}

export function getWecomShareLinkLogisticsJob(jobKey) {
  return request({
    url: '/jarvis/wecom/shareLinkLogisticsJob/' + encodeURIComponent(jobKey),
    method: 'get'
  })
}

export function backfillShareLinkLogisticsFromTrace() {
  return request({
    url: '/jarvis/wecom/shareLinkLogisticsJob/backfillFromInboundTrace',
    method: 'post'
  })
}

/** 与订单列表「获取物流」一致：立即查物流并推送 */
export function fetchShareLinkManually(data) {
  return request({
    url: '/jarvis/wecom/shareLinkLogisticsJob/fetchShareLinkManually',
    method: 'post',
    data
  })
}

/** 手动执行一轮 Redis 待扫描队列（同定时任务） */
export function drainShareLinkPendingQueueOnce() {
  return request({
    url: '/jarvis/wecom/shareLinkLogisticsJob/drainPendingQueueOnce',
    method: 'post'
  })
}

/** 取消扫描：状态改为 CANCELLED，不再对账入队；队列弹出时跳过 */
export function cancelWecomShareLinkJob(data) {
  return request({
    url: '/jarvis/wecom/shareLinkLogisticsJob/cancel',
    method: 'post',
    data
  })
}

/** 删除任务行（Redis 中残留同 jobKey 项弹出时会因无库行而跳过） */
export function removeWecomShareLinkJob(jobKey) {
  return request({
    url: '/jarvis/wecom/shareLinkLogisticsJob/' + encodeURIComponent(jobKey),
    method: 'delete'
  })
}
