import { isApplicationRequestLike } from './documentClassification.js'

const APPLICATION_ARCHIVE_STAGE = '申请归档'

export function isArchivedExpenseClaim(claim) {
  const stage = String(claim?.approval_stage || claim?.approvalStage || '').trim()
  const status = String(claim?.status || '').trim().toLowerCase()

  if (isApplicationRequestLike(claim)) {
    return stage === APPLICATION_ARCHIVE_STAGE
      && ['approved', 'completed', 'paid'].includes(status)
  }

  if (stage === '归档入账' || stage === '已付款' || stage === 'completed' || stage.includes('归档')) {
    return true
  }

  if (!['approved', 'completed', 'paid'].includes(status)) {
    return false
  }

  if (stage === APPLICATION_ARCHIVE_STAGE) {
    return true
  }

  return !stage || stage === '归档入账' || stage === '已付款' || stage === 'completed'
}
