import { createI18n } from 'vue-i18n'
import { describe, expect, it } from 'vitest'

import zhCN from '@/i18n/locales/zh-CN'
import {
  formatReservationActorType,
  formatReservationReadonlyReason,
  formatReservationTaskTypeSummary,
} from '@/utils/reservationDisplay'

const i18n = createI18n({
  legacy: false,
  locale: 'zh-CN',
  messages: {
    'zh-CN': zhCN,
  },
})

describe('reservationDisplay', () => {
  it('formats known task type and subtype codes without exposing duplicated raw codes', () => {
    expect(formatReservationTaskTypeSummary(i18n.global.t, 'NEW_BOOKING', 'NEW_BOOKING')).toBe('新预订')
    expect(formatReservationTaskTypeSummary(i18n.global.t, 'UPDATE_BOOKING', 'RATE_CHANGE')).toBe('修改预订 / 价格调整')
  })

  it('formats readonly reason and actor codes with user-facing labels', () => {
    expect(formatReservationReadonlyReason(i18n.global.t, 'PREVIOUS_TASK_NOT_FINISHED')).toBe('前序任务未完成')
    expect(formatReservationActorType(i18n.global.t, 'USER')).toBe('人工用户')
  })

  it('uses localized fallback labels for unknown stable codes', () => {
    expect(formatReservationReadonlyReason(i18n.global.t, 'SOME_BACKEND_CODE')).toBe('暂不可处理')
  })
})
