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

import {
  DOCUMENT_TYPE_APPLICATION,
  DOCUMENT_TYPE_LABELS,
  DOCUMENT_TYPE_REIMBURSEMENT,
  INLINE_APPLICATION_STATUS_LABELS,
  resolveDocumentTypeLabel
} from '../src/constants/documentProtocol.js'
import { readSourceFile, readSourceSurface } from './helpers/sourceSurface.mjs'

test('document protocol constants centralize document types and labels', () => {
  assert.equal(DOCUMENT_TYPE_APPLICATION, 'application')
  assert.equal(DOCUMENT_TYPE_REIMBURSEMENT, 'reimbursement')
  assert.equal(DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_APPLICATION], '申请单')
  assert.equal(DOCUMENT_TYPE_LABELS[DOCUMENT_TYPE_REIMBURSEMENT], '报销单')
  assert.equal(resolveDocumentTypeLabel('application'), '申请单')
  assert.equal(resolveDocumentTypeLabel('expense_application'), '申请单')
  assert.equal(resolveDocumentTypeLabel('unknown', '单据'), '单据')
})

test('inline application status labels live in the shared document protocol', () => {
  assert.equal(INLINE_APPLICATION_STATUS_LABELS.draft, '草稿')
  assert.equal(INLINE_APPLICATION_STATUS_LABELS.submitted, '审批中')
  assert.equal(INLINE_APPLICATION_STATUS_LABELS.pending_payment, '待付款')
})

test('source surface helper loads one or more source files for source assertions', () => {
  const model = readSourceFile('constants/documentProtocol.js')
  assert.match(model, /DOCUMENT_TYPE_APPLICATION/)

  const combined = readSourceSurface([
    'constants/documentProtocol.js',
    'composables/workbenchAiMode/workbenchAiApplicationPreviewModel.js'
  ])
  assert.match(combined, /INLINE_APPLICATION_STATUS_LABELS/)
  assert.match(combined, /normalizeInlineApplicationStatusLabel/)
})
