const APPLICATION_DOCUMENT_NO_PATTERN = /^A[A-HJ-NP-Z2-9]{8}$/i

export function isApplicationDocumentNo(value) {
  const claimNo = String(value || '').trim().toUpperCase()
  return (
    APPLICATION_DOCUMENT_NO_PATTERN.test(claimNo)
    || claimNo.startsWith('AP-')
    || claimNo.startsWith('APP-')
  )
}

export function isApplicationRequestLike(value) {
  const explicitType = String(
    value?.documentTypeCode
    || value?.document_type_code
    || value?.documentType
    || value?.document_type
    || ''
  ).trim()
  const claimNo = String(value?.claim_no || value?.claimNo || value?.documentNo || value?.id || '')
    .trim()
    .toUpperCase()
  const typeCode = String(value?.typeCode || value?.expense_type || value?.expenseType || '').trim()

  return (
    explicitType === 'application'
    || explicitType === 'expense_application'
    || isApplicationDocumentNo(claimNo)
    || typeCode === 'application'
    || typeCode.endsWith('_application')
  )
}
