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

import {
  isKuaishouIndustryEticketDestroyableStatus,
  resolveKuaishouIndustryEticketDisplayStatus,
} from './check-available-service.js'

test('resolveKuaishouIndustryEticketDisplayStatus 按券码读取展示状态', () => {
  const response = {
    etickets: [
      { code: 'OTHER-CODE', displayStatus: 'available' },
      { code: 'TARGET-CODE', displayStatus: ' Frozen ' },
    ],
  }

  assert.equal(resolveKuaishouIndustryEticketDisplayStatus(response, 'target-code'), 'frozen')
  assert.equal(isKuaishouIndustryEticketDestroyableStatus('frozen'), true)
})

test('resolveKuaishouIndustryEticketDisplayStatus 兼容 data 内的 status 字段', () => {
  const response = {
    data: {
      eTicketList: [{ id: 'TARGET-CODE', status: 'FROZEN' }],
    },
  }

  assert.equal(resolveKuaishouIndustryEticketDisplayStatus(response, 'TARGET-CODE'), 'frozen')
})

test('isKuaishouIndustryEticketDestroyableStatus 拒绝非冻结和缺失状态', () => {
  assert.equal(isKuaishouIndustryEticketDestroyableStatus('available'), false)
  assert.equal(isKuaishouIndustryEticketDestroyableStatus(''), false)
})

test('resolveKuaishouIndustryEticketDisplayStatus 拒绝其他券码的冻结状态', () => {
  assert.equal(
    resolveKuaishouIndustryEticketDisplayStatus(
      { etickets: [{ code: 'OTHER-CODE', displayStatus: 'frozen' }] },
      'TARGET-CODE',
    ),
    '',
  )
})
