import test from 'node:test'
import assert from 'node:assert/strict'

import {
  TASK_STATUS,
  canRedeemKuaishouCloudClaimStatus,
  canTaskTransition,
  isClaimInactiveTaskStatus,
  isOpen91FailedTaskStatus,
  shouldEnsureKuaishouCloudClaimLink,
} from './task-status.js'

test('任务状态机声明 kuaishou-lewan 主流程跳转', () => {
  assert.equal(
    canTaskTransition(TASK_STATUS.PENDING_BINDING_PREPARE, TASK_STATUS.WAITING_BINDING),
    true,
  )
  assert.equal(canTaskTransition(TASK_STATUS.WAITING_BINDING, TASK_STATUS.ROLE_CONFIRMED), true)
  assert.equal(canTaskTransition(TASK_STATUS.ROLE_CONFIRMED, TASK_STATUS.REDEEMING), true)
  assert.equal(
    canTaskTransition(TASK_STATUS.REDEEMING, TASK_STATUS.DISPATCHED_PENDING_RETURN),
    true,
  )
  assert.equal(
    canTaskTransition(TASK_STATUS.DISPATCHED_PENDING_RETURN, TASK_STATUS.COMPLETED),
    true,
  )
})

test('任务状态机收敛领取和 91 查询的业务判断', () => {
  assert.equal(shouldEnsureKuaishouCloudClaimLink(TASK_STATUS.PENDING_BINDING_PREPARE), true)
  assert.equal(canRedeemKuaishouCloudClaimStatus(TASK_STATUS.ROLE_CONFIRMED), true)
  assert.equal(canRedeemKuaishouCloudClaimStatus(TASK_STATUS.WAITING_BINDING), true)
  assert.equal(canRedeemKuaishouCloudClaimStatus(TASK_STATUS.LINK_GENERATED), false)
  assert.equal(isClaimInactiveTaskStatus(TASK_STATUS.MANUAL_REVIEW), true)
  assert.equal(isOpen91FailedTaskStatus(TASK_STATUS.CLOSED), true)
})
