<reponame>ccetc/mahaplatform.com<gh_stars>0
import { getSubscriptionTokens } from '@apps/subscriptions/services/subscriptions'
import { getRegistrationTokens } from '@apps/events/services/registrations'
import { getRenewalTokens } from '@apps/subscriptions/services/renewals'
import { getResponseTokens } from '@apps/forms/services/responses'
import { getContactTokens } from '@apps/crm/services/contacts'
import { getProgramTokens } from '@apps/crm/services/programs'
import { getOrderTokens } from '@apps/stores/services/orders'

const getEnrollmentTokens = async (req, { contact, enrollment, program }) => ({
  contact: await getContactTokens(req, {
    contact_id: contact.get('id')
  }),
  program: await getProgramTokens(req, {
    contact_id: contact.get('id'),
    program_id: program.get('id')
  }),
  ...enrollment.get('registration_id') ? {
    registration: await getRegistrationTokens(req, {
      registration_id: enrollment.get('registration_id')
    })
  } : {},
  ...enrollment.get('response_id') ? {
    response: await getResponseTokens(req, {
      response_id: enrollment.get('response_id')
    })
  } : {},
  ...enrollment.get('order_id') ? {
    order: await getOrderTokens(req, {
      order_id: enrollment.get('order_id')
    })
  } : {},
  ...enrollment.get('subscription_id') ? {
    subscription: await getSubscriptionTokens(req, {
      subscription_id: enrollment.get('subscription_id')
    })
  } : {},
  ...enrollment.get('renewal_id') ? {
    renewal: await getRenewalTokens(req, {
      renewal_id: enrollment.get('renewal_id')
    })
  } : {},
  workflow: enrollment.get('data')
})

export default getEnrollmentTokens
