import {
  APPLICATION_ARCHIVE_STAGE_LABEL,
  APPLICATION_LINK_STATUS_STEP_LABEL,
  APPLICATION_PROGRESS_LABELS,
  APPLICATION_PROGRESS_LABELS_WITHOUT_BUDGET,
  ARCHIVED_STEP_LABEL,
  DOCUMENT_TYPE_APPLICATION,
  RELATED_APPLICATION_STEP_LABEL,
  REIMBURSEMENT_PROGRESS_LABELS,
  formatDateTime,
  formatDurationFrom,
  getLatestEvent,
  getRiskFlags,
  normalizeText,
  parseNumber,
  resolveDisplayName
} from './requestShared.js'
import { resolveRelatedApplicationInfo } from './requestRelatedApplication.js'

function resolveProgressCurrentIndex(approvalMeta, workflowNode) {
  const normalizedNode = String(workflowNode || '').trim()

  if (approvalMeta.key === 'completed') {
    return 6
  }

  if (approvalMeta.key === 'pending_payment') {
    return 4
  }

  if (normalizedNode.includes('已付款')) {
    return 5
  }
  if (normalizedNode.includes('待付款')) {
    return 4
  }
  if (normalizedNode.includes('归档') || normalizedNode.includes('入账')) {
    return 6
  }
  if (normalizedNode.includes('财务')) {
    return 3
  }
  if (
    normalizedNode.includes('直属领导')
    || normalizedNode.includes('领导审批')
    || normalizedNode.includes('部门负责人')
    || normalizedNode.includes('负责人审批')
  ) {
    return 2
  }
  if (normalizedNode.includes('AI预审') || normalizedNode.includes('AI验审') || normalizedNode.includes('审批流转')) {
    return approvalMeta.key === 'draft' || approvalMeta.key === 'supplement' ? 1 : 2
  }
  if (normalizedNode.includes('待提交')) {
    return 1
  }

  if (approvalMeta.key === 'draft' || approvalMeta.key === 'supplement' || approvalMeta.key === 'rejected') {
    return 1
  }

  return 2
}

function resolveApplicationProgressCurrentIndex(approvalMeta, workflowNode) {
  const normalizedNode = String(workflowNode || '').trim()

  if (approvalMeta.key === 'completed') {
    return normalizedNode.includes(APPLICATION_ARCHIVE_STAGE_LABEL) ? 3 : 2
  }

  if (normalizedNode.includes(APPLICATION_ARCHIVE_STAGE_LABEL) || normalizedNode.includes(ARCHIVED_STEP_LABEL)) {
    return 3
  }
  if (normalizedNode.includes(APPLICATION_LINK_STATUS_STEP_LABEL)) {
    return 2
  }
  if (normalizedNode.includes('审批完成') || normalizedNode.includes('申请完成')) {
    return 2
  }
  if (normalizedNode.includes('预算')) {
    return 2
  }
  if (
    normalizedNode.includes('直属领导')
    || normalizedNode.includes('领导审批')
    || normalizedNode.includes('部门负责人')
    || normalizedNode.includes('负责人审批')
  ) {
    return 1
  }
  if (approvalMeta.key === 'draft' || approvalMeta.key === 'supplement' || approvalMeta.key === 'rejected') {
    return 0
  }

  return 1
}

function isApplicationArchivedWorkflow(claim, workflowNode) {
  const normalizedNode = normalizeText(workflowNode || claim?.approval_stage || claim?.workflowNode)
  if (normalizedNode.includes(APPLICATION_ARCHIVE_STAGE_LABEL) || normalizedNode.includes(ARCHIVED_STEP_LABEL)) {
    return true
  }
  return getRiskFlags(claim).some((flag) => (
    flag
    && typeof flag === 'object'
    && normalizeText(flag.source) === 'application_archive_sync'
  ))
}

function resolveApplicationLinkedReimbursementNo(claim) {
  for (const flag of [...getRiskFlags(claim)].reverse()) {
    if (!flag || typeof flag !== 'object') {
      continue
    }
    const generatedNo = normalizeText(
      flag.generated_draft_claim_no
      || flag.generatedDraftClaimNo
      || flag.reimbursement_claim_no
      || flag.reimbursementClaimNo
    )
    if (generatedNo) {
      return generatedNo
    }
  }
  return ''
}

function buildApplicationLinkStatusStepMeta(claim) {
  const reimbursementNo = resolveApplicationLinkedReimbursementNo(claim)
  const updatedAt = formatDateTime(claim?.updated_at)
  return reimbursementNo
    ? buildProgressStepMeta(`关联中 ${reimbursementNo}`, updatedAt)
    : buildProgressStepMeta('未关联', updatedAt)
}


function resolveApplicationApproverName(claim) {
  return resolveDisplayName(
    claim?.manager_name,
    claim?.managerName,
    claim?.profile_manager,
    claim?.profileManager,
    claim?.direct_manager_name,
    claim?.directManagerName
  ) || '直属领导'
}

function resolveReimbursementApproverName(claim, label) {
  const stepLabel = normalizeText(label)
  if (stepLabel === '直属领导审批') {
    return resolveDisplayName(
      claim?.manager_name,
      claim?.managerName,
      claim?.profile_manager,
      claim?.profileManager,
      claim?.direct_manager_name,
      claim?.directManagerName
    ) || '直属领导'
  }

  if (stepLabel === '财务审批') {
    const routeEvent = findReimbursementFinanceRouteEvent(claim)
    return resolveDisplayName(
      claim?.finance_approver_name,
      claim?.financeApproverName,
      routeEvent?.next_approver_name,
      routeEvent?.nextApproverName,
      routeEvent?.finance_approver_name,
      routeEvent?.financeApproverName,
      claim?.finance_owner_name,
      claim?.financeOwnerName
    ) || '财务'
  }

  return stepLabel.replace(/审批$/, '') || '审批人'
}

function resolveApplicationBudgetApproverName(claim) {
  const routeEvent = findApprovalEventForStep(claim, '直属领导审批')
  return resolveDisplayName(
    claim?.budget_approver_name,
    claim?.budgetApproverName,
    routeEvent?.next_approver_name,
    routeEvent?.nextApproverName,
    routeEvent?.budget_approver_name,
    routeEvent?.budgetApproverName
  ) || '预算管理者'
}

function resolveProgressDisplayLabel(label, documentTypeCode, claim, approvalMeta) {
  const normalizedLabel = normalizeText(label)
  const workflowNode = normalizeText(claim?.approval_stage || claim?.workflowNode)
  if (
    documentTypeCode !== DOCUMENT_TYPE_APPLICATION
    && approvalMeta.key !== 'completed'
    && normalizedLabel === '直属领导审批'
    && workflowNode.includes(normalizedLabel.replace(/审批$/, ''))
  ) {
    return '等待批复'
  }

  if (
    documentTypeCode !== DOCUMENT_TYPE_APPLICATION
    && approvalMeta.key !== 'completed'
    && normalizedLabel === '财务审批'
    && workflowNode.includes(normalizedLabel.replace(/审批$/, ''))
  ) {
    return `等待 ${resolveReimbursementApproverName(claim, normalizedLabel)} 批复`
  }

  if (
    documentTypeCode === DOCUMENT_TYPE_APPLICATION
    && approvalMeta.key !== 'completed'
    && normalizedLabel === '直属领导审批'
    && (
      workflowNode.includes('直属领导')
      || workflowNode.includes('领导审批')
      || workflowNode.includes('部门负责人')
      || workflowNode.includes('负责人审批')
    )
  ) {
    return `等待 ${resolveApplicationApproverName(claim)} 批复`
  }

  if (
    documentTypeCode === DOCUMENT_TYPE_APPLICATION
    && approvalMeta.key !== 'completed'
    && normalizedLabel === '预算管理者审批'
    && workflowNode.includes('预算')
  ) {
    return `等待 ${resolveApplicationBudgetApproverName(claim)} 批复`
  }

  return label
}


function findApprovalEventForStep(claim, label) {
  const stepLabel = normalizeText(label)
  const events = getRiskFlags(claim).filter((flag) => {
    if (!flag || typeof flag !== 'object') {
      return false
    }

    const source = normalizeText(flag.source)
    if (!['manual_approval', 'budget_approval', 'finance_approval'].includes(source)) {
      return false
    }

    const previousStage = normalizeText(flag.previous_approval_stage || flag.previousApprovalStage)
    const nextStage = normalizeText(flag.next_approval_stage || flag.nextApprovalStage)

    if (stepLabel === '直属领导审批') {
      return (
        previousStage.includes('直属领导')
        || previousStage.includes('领导审批')
        || nextStage.includes('预算')
        || nextStage.includes('财务')
      )
    }

    if (stepLabel === '预算管理者审批') {
      return (
        source === 'budget_approval'
        || previousStage.includes('预算')
        || nextStage.includes('审批完成')
      )
    }

    if (stepLabel === '财务审批') {
      return (
        previousStage.includes('财务')
        || nextStage.includes('待付款')
        || nextStage.includes('归档')
        || nextStage.includes('入账')
        || nextStage.includes('完成')
      )
    }

    return false
  })

  return getLatestEvent(events)
}

function findReimbursementFinanceRouteEvent(claim) {
  return getLatestEvent(
    getRiskFlags(claim).filter((flag) => {
      if (!flag || typeof flag !== 'object') {
        return false
      }

      const source = normalizeText(flag.source)
      if (!['manual_approval', 'budget_approval'].includes(source)) {
        return false
      }

      const nextStage = normalizeText(flag.next_approval_stage || flag.nextApprovalStage)
      return nextStage.includes('财务')
    })
  )
}

function findLatestReturnEvent(claim) {
  return getLatestEvent(
    getRiskFlags(claim).filter((flag) => (
      flag
      && typeof flag === 'object'
      && normalizeText(flag.source) === 'manual_return'
    ))
  )
}

function findLatestPaymentEvent(claim) {
  return getLatestEvent(
    getRiskFlags(claim).filter((flag) => (
      flag
      && typeof flag === 'object'
      && (
        normalizeText(flag.source) === 'payment'
        || normalizeText(flag.event_type || flag.eventType) === 'expense_claim_payment_completed'
      )
    ))
  )
}


function findLatestApplicationReturnEvent(claim) {
  return getLatestEvent(
    getRiskFlags(claim).filter((flag) => {
      if (!flag || typeof flag !== 'object' || normalizeText(flag.source) !== 'manual_return') {
        return false
      }
      const eventType = normalizeText(flag.event_type || flag.eventType)
      const returnStage = normalizeText(flag.return_stage || flag.returnStage || flag.previous_approval_stage)
      const stageKey = normalizeText(flag.return_stage_key || flag.returnStageKey)
      return (
        eventType === 'expense_application_return'
        || stageKey === 'direct_manager'
        || returnStage.includes('直属领导')
        || returnStage.includes('领导审批')
      )
    })
  )
}

function findMergedApplicationBudgetApprovalEvent(claim) {
  return getLatestEvent(
    getRiskFlags(claim).filter((flag) => {
      if (!flag || typeof flag !== 'object') {
        return false
      }
      const source = normalizeText(flag.source)
      const eventType = normalizeText(flag.event_type || flag.eventType)
      const previousStage = normalizeText(flag.previous_approval_stage || flag.previousApprovalStage)
      const nextStage = normalizeText(flag.next_approval_stage || flag.nextApprovalStage)
      const mergedFlag = Boolean(flag.budget_approval_merged || flag.budgetApprovalMerged)
      return (
        source === 'manual_approval'
        && eventType === 'expense_application_approval'
        && previousStage.includes('直属领导')
        && (
          nextStage.includes('审批完成')
          || nextStage.includes(APPLICATION_LINK_STATUS_STEP_LABEL)
          || nextStage.includes('申请完成')
        )
        && mergedFlag
      )
    })
  )
}

function resolveBudgetRouteResult(flag, routeDecision = {}) {
  if (routeDecision && typeof routeDecision === 'object') {
    const routeBudgetResult = routeDecision.budget_result || routeDecision.budgetResult
    if (routeBudgetResult && typeof routeBudgetResult === 'object') {
      return routeBudgetResult
    }
  }

  const flagBudgetResult = flag?.budget_result || flag?.budgetResult
  return flagBudgetResult && typeof flagBudgetResult === 'object' ? flagBudgetResult : {}
}

function applicationBudgetRouteMeetsThreshold(flag, routeDecision = {}) {
  const budgetResult = resolveBudgetRouteResult(flag, routeDecision)
  const metrics = budgetResult.metrics && typeof budgetResult.metrics === 'object' ? budgetResult.metrics : {}
  const overBudgetAmount = parseNumber(metrics.over_budget_amount ?? metrics.overBudgetAmount)
  const afterUsageRate = parseNumber(metrics.after_usage_rate ?? metrics.afterUsageRate)
  const claimAmountRatio = parseNumber(metrics.claim_amount_ratio ?? metrics.claimAmountRatio)

  return overBudgetAmount > 0 || Math.max(afterUsageRate, claimAmountRatio) >= 90
}

function applicationRequiresBudgetReviewStep(claim, workflowNode) {
  const node = normalizeText(workflowNode || claim?.approval_stage || claim?.workflowNode)
  if (node.includes('预算')) {
    return true
  }

  return getRiskFlags(claim).some((flag) => {
    if (!flag || typeof flag !== 'object') {
      return false
    }

    const source = normalizeText(flag.source)
    const eventType = normalizeText(flag.event_type || flag.eventType)
    const previousStage = normalizeText(flag.previous_approval_stage || flag.previousApprovalStage)
    const routeDecision = flag.route_decision || flag.routeDecision || {}

    if (source === 'approval_routing' && flag.requires_budget_review === true) {
      return applicationBudgetRouteMeetsThreshold(flag, flag)
    }
    if (
      routeDecision
      && typeof routeDecision === 'object'
      && routeDecision.requires_budget_review === true
    ) {
      return applicationBudgetRouteMeetsThreshold(flag, routeDecision)
    }
    return (
      source === 'budget_approval'
      || eventType === 'expense_application_budget_approval'
      || previousStage.includes('预算')
    )
  })
}

function buildProgressStepMeta(time, detail = '', title = '') {
  return {
    time,
    detail,
    title: title || [time, detail].filter(Boolean).join(' ')
  }
}

function buildCompletedStepMeta(claim, label) {
  const stepLabel = normalizeText(label)
  const employeeName = normalizeText(claim?.employee_name) || '申请人'

  if (stepLabel === RELATED_APPLICATION_STEP_LABEL) {
    const relatedApplication = resolveRelatedApplicationInfo(claim)
    const createdAt = formatDateTime(claim?.created_at)
    if (relatedApplication?.claimNo) {
      return buildProgressStepMeta(`已关联 ${relatedApplication.claimNo}`, createdAt)
    }
    return buildProgressStepMeta('待核对关联单据', createdAt)
  }

  if (stepLabel === APPLICATION_LINK_STATUS_STEP_LABEL) {
    return buildApplicationLinkStatusStepMeta(claim)
  }

  if (stepLabel === '创建单据' || stepLabel === '创建申请') {
    const createdAt = formatDateTime(claim?.created_at)
    return buildProgressStepMeta(stepLabel === '创建申请' ? `${employeeName}发起申请` : `${employeeName}创建`, createdAt)
  }

  if (stepLabel === '待提交') {
    const submittedAt = formatDateTime(claim?.submitted_at)
    return buildProgressStepMeta(`${employeeName}提交`, submittedAt)
  }

  if (stepLabel === '直属领导审批' || stepLabel === '预算管理者审批' || stepLabel === '财务审批') {
    const approvalEvent = findApprovalEventForStep(claim, stepLabel)
    if (approvalEvent) {
      const operator = resolveDisplayName(
        approvalEvent.operator,
        approvalEvent.operator_name,
        approvalEvent.operatorName,
        stepLabel === '直属领导审批' ? claim?.manager_name : '',
        stepLabel === '预算管理者审批' ? approvalEvent.next_approver_name : ''
      ) || (stepLabel === '财务审批' ? '财务' : stepLabel === '预算管理者审批' ? '预算管理者' : '直属领导')
      const approvedAt = formatDateTime(approvalEvent.created_at || approvalEvent.createdAt)
      return buildProgressStepMeta(`${operator}通过`, approvedAt, `${operator}审批通过 ${approvedAt}`.trim())
    }

    if (stepLabel === '财务审批') {
      const updatedAt = formatDateTime(claim?.updated_at)
      return buildProgressStepMeta('财务通过', updatedAt, `财务审批通过 ${updatedAt}`.trim())
    }

    if (stepLabel === '直属领导审批') {
      const returnEvent = findLatestApplicationReturnEvent(claim)
      if (returnEvent) {
        const handledAt = formatDateTime(returnEvent.created_at || returnEvent.createdAt)
        return buildProgressStepMeta('已处理', handledAt, `直属领导已处理 ${handledAt}`.trim())
      }
    }
  }

  if (stepLabel === '退回') {
    const returnEvent = findLatestApplicationReturnEvent(claim) || findLatestReturnEvent(claim)
    if (returnEvent) {
      const operator = resolveDisplayName(
        returnEvent.operator,
        returnEvent.operator_name,
        returnEvent.operatorName,
        claim?.manager_name
      ) || '直属领导'
      const returnedAt = formatDateTime(returnEvent.created_at || returnEvent.createdAt)
      return buildProgressStepMeta(`${operator}退回`, returnedAt, `${operator}退回 ${returnedAt}`.trim())
    }
  }

  if (stepLabel === '待付款') {
    const approvalEvent = findApprovalEventForStep(claim, '财务审批')
    const pendingAt = formatDateTime(approvalEvent?.created_at || approvalEvent?.createdAt || claim?.updated_at)
    return buildProgressStepMeta('待付款', pendingAt)
  }

  if (stepLabel === '已付款') {
    const paymentEvent = findLatestPaymentEvent(claim)
    const paidAt = formatDateTime(paymentEvent?.created_at || paymentEvent?.createdAt || claim?.updated_at)
    return buildProgressStepMeta('已付款', paidAt)
  }

  if (stepLabel === '归档入账') {
    const archivedAt = formatDateTime(claim?.updated_at)
    return buildProgressStepMeta('归档入账', archivedAt)
  }

  if (stepLabel === ARCHIVED_STEP_LABEL) {
    const archivedAt = formatDateTime(claim?.updated_at)
    return buildProgressStepMeta(ARCHIVED_STEP_LABEL, archivedAt)
  }

  if (stepLabel === '审批完成') {
    const completedAt = formatDateTime(claim?.updated_at)
    return buildProgressStepMeta('审批完成', completedAt)
  }

  return buildProgressStepMeta('已完成')
}

function resolveCurrentStepStartedAt(claim, label) {
  const stepLabel = normalizeText(label)
  if (stepLabel === RELATED_APPLICATION_STEP_LABEL || stepLabel === '创建单据' || stepLabel === '创建申请') {
    return claim?.created_at
  }
  if (stepLabel === '待提交') {
    const returnEvent = findLatestReturnEvent(claim)
    return returnEvent?.created_at || returnEvent?.createdAt || claim?.updated_at || claim?.created_at
  }
  if (stepLabel === '直属领导审批') {
    return claim?.submitted_at || claim?.updated_at || claim?.created_at
  }
  if (stepLabel === '预算管理者审批') {
    const leaderApprovalEvent = findApprovalEventForStep(claim, '直属领导审批')
    return leaderApprovalEvent?.created_at || leaderApprovalEvent?.createdAt || claim?.updated_at || claim?.submitted_at
  }
  if (stepLabel === '财务审批') {
    const leaderApprovalEvent = findApprovalEventForStep(claim, '直属领导审批')
    return leaderApprovalEvent?.created_at || leaderApprovalEvent?.createdAt || claim?.updated_at || claim?.submitted_at
  }
  if (stepLabel === '待付款') {
    const approvalEvent = findApprovalEventForStep(claim, '财务审批')
    return approvalEvent?.created_at || approvalEvent?.createdAt || claim?.updated_at || claim?.submitted_at
  }
  if (stepLabel === '已付款') {
    const paymentEvent = findLatestPaymentEvent(claim)
    return paymentEvent?.created_at || paymentEvent?.createdAt || claim?.updated_at || claim?.submitted_at
  }
  if (stepLabel === '归档入账' || stepLabel === ARCHIVED_STEP_LABEL || stepLabel === '审批完成') {
    return claim?.updated_at || claim?.submitted_at
  }
  return ''
}

function buildProgressSteps(approvalMeta, workflowNode, claim = {}, options = {}) {
  const documentTypeCode = String(options.documentTypeCode || '').trim()
  const hasApplicationReturnStep = (
    documentTypeCode === DOCUMENT_TYPE_APPLICATION
    && Boolean(findLatestApplicationReturnEvent(claim))
    && approvalMeta.key === 'supplement'
  )
  const hasMergedApplicationBudgetApproval = (
    documentTypeCode === DOCUMENT_TYPE_APPLICATION
    && Boolean(findMergedApplicationBudgetApprovalEvent(claim))
  )
  const shouldShowApplicationBudgetStep = (
    documentTypeCode === DOCUMENT_TYPE_APPLICATION
    && !hasMergedApplicationBudgetApproval
    && applicationRequiresBudgetReviewStep(claim, workflowNode)
  )
  const isApplicationDocument = documentTypeCode === DOCUMENT_TYPE_APPLICATION
  const applicationArchived = isApplicationDocument && isApplicationArchivedWorkflow(claim, workflowNode)
  const progressLabels =
    isApplicationDocument
      ? hasApplicationReturnStep
        ? ['创建申请', '直属领导审批', '退回', '待提交']
        : hasMergedApplicationBudgetApproval
          ? ['创建申请', '直属领导审批', APPLICATION_LINK_STATUS_STEP_LABEL, ARCHIVED_STEP_LABEL]
          : shouldShowApplicationBudgetStep
            ? APPLICATION_PROGRESS_LABELS
            : APPLICATION_PROGRESS_LABELS_WITHOUT_BUDGET
      : REIMBURSEMENT_PROGRESS_LABELS
  const applicationLinkIndex = progressLabels.indexOf(APPLICATION_LINK_STATUS_STEP_LABEL)
  const applicationArchiveIndex = progressLabels.indexOf(ARCHIVED_STEP_LABEL)
  const currentIndex =
    isApplicationDocument
      ? hasApplicationReturnStep
        ? 3
        : applicationArchived && applicationArchiveIndex >= 0
          ? applicationArchiveIndex
          : approvalMeta.key === 'completed' && applicationLinkIndex >= 0
            ? applicationLinkIndex
            : Math.min(
              resolveApplicationProgressCurrentIndex(approvalMeta, workflowNode),
              Math.max(0, progressLabels.length - 1)
            )
      : resolveProgressCurrentIndex(approvalMeta, workflowNode)
  const currentTime =
    approvalMeta.key === 'completed'
      ? '已完成'
      : approvalMeta.key === 'pending_payment'
        ? '待付款'
      : approvalMeta.key === 'supplement'
        ? '待补充'
        : approvalMeta.key === 'rejected'
          ? '已退回'
          : '进行中'

  return progressLabels.map((label, index) => {
    const displayLabel = resolveProgressDisplayLabel(label, documentTypeCode, claim, approvalMeta)
    if (approvalMeta.key === 'completed' && (!isApplicationDocument || applicationArchived)) {
      const stepMeta = buildCompletedStepMeta(claim, label)
      return {
        index: index + 1,
        label: displayLabel,
        rawLabel: label,
        time: stepMeta.time,
        detail: stepMeta.detail,
        title: stepMeta.title,
        done: true,
        active: true,
        current: false
      }
    }

    if (index < currentIndex) {
      const stepMeta = buildCompletedStepMeta(claim, label)
      return {
        index: index + 1,
        label: displayLabel,
        rawLabel: label,
        time: stepMeta.time,
        detail: stepMeta.detail,
        title: stepMeta.title,
        done: true,
        active: true,
        current: false
      }
    }

    if (index === currentIndex) {
      if (isApplicationDocument && label === APPLICATION_LINK_STATUS_STEP_LABEL) {
        const stepMeta = buildApplicationLinkStatusStepMeta(claim)
        return {
          index: index + 1,
          label: displayLabel,
          rawLabel: label,
          time: stepMeta.time,
          detail: stepMeta.detail,
          title: stepMeta.title,
          done: false,
          active: true,
          current: true
        }
      }
      const stayDuration = formatDurationFrom(resolveCurrentStepStartedAt(claim, label))
      return {
        index: index + 1,
        label: displayLabel,
        rawLabel: label,
        time: stayDuration ? `停留 ${stayDuration}` : currentTime,
        detail: '',
        title: stayDuration ? `当前${displayLabel}已停留 ${stayDuration}` : currentTime,
        done: false,
        active: true,
        current: true
      }
    }

    return {
      index: index + 1,
      label: displayLabel,
      rawLabel: label,
      time: '待处理',
      detail: '',
      title: '待处理',
      done: false,
      active: false,
      current: false
    }
  })
}

export {
  buildProgressSteps,
  isApplicationArchivedWorkflow,
  resolveApplicationLinkedReimbursementNo
}
