export function isSubmittedApplicationDraftPayload(draftPayload) {
  return (
    String(draftPayload?.draft_type || '').trim() === 'expense_application'
    && String(draftPayload?.status || '').trim() === 'submitted'
  )
}

export function buildOperationFeedbackState(context) {
  if (!context) {
    return null
  }
  return {
    context,
    submitting: false,
    submitted: false,
    dismissed: false,
    rating: 0,
    reason: '',
    error: ''
  }
}

export function resolveAssistantResultText(payload, fallbackAnswer) {
  const result = payload?.result && typeof payload.result === 'object' ? payload.result : {}
  if (isSubmittedApplicationDraftPayload(result.draft_payload)) {
    return ''
  }
  return result.answer || result.message || fallbackAnswer
}
