function handleWelcomeEmail(user) {
  const emailsRef = db.collection("welcomeEmails");

  db.collection("welcomeEmailCarbonCopy").doc("carbonCopy").get().then(doc => {
    createWelcomeEmailDoc(user, emailsRef, doc);
  }).catch(function(error) {
    console.log(`ERROR fetching cc field for welcome email. Email not sent:`, error)
  });
}

function createWelcomeEmailDoc(user, emailsRef, doc) {
  console.log(`Creating welcome email with cc and bcc fields`)
  emailsRef.doc().set({
    to: [user.email],
    cc: doc.get("cc"),
    bcc: doc.get("bcc"),
    message: {
      subject: 'Welcome to Attorney Academy',
      text: plaintextBody(user),
      html: htmlBody(user),
    },
    userId: user.uid,
  })
}

function plaintextBody(user) {
  return `
WELCOME TO THE ATTORNEY ACADEMY ON REASONABLE EFFORTS

In this course, you will learn how to make meaningful reasonable efforts arguments in a child welfare case. The course is composed of three parts:

  • Part 1: An online pre-workshop assessment of your current knowledge, including a learner performance report that provides answers to the questions,
  • Part 2: Two days of in-person instruction centered around interactive simulations in a live classroom environment, with experts present to help you refine your skills, and
  • Part 3: An online post-workshop assessment so you can see your improvements after the training.

This pre-test assessment should take you about fifteen minutes to complete. You may take the online assessment on your computer, tablet, or phone. After completing the online assessment, you will have access to a learner performance report that provides answers and explanations to the questions.

Please use the same email address to log in and out of the online portion of the course. Using the same email insures we can link your work throughout the course so you can track your improvements. Once you have completed the pre-workshop assessment do not go on to complete the post-test assessment. Simply log out of the course or close your browser window. You will be given time at the end of the live training to complete and review the post-workshop assessment.

The online portion of the course work best on Safari, Chrome, Microsoft Edge, or Firefox.

<<<*** It does not work on Internet Explorer. ***>>>
`
}

function htmlBody(user) {
  return `
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        </head>
        <body>
          <h3>
            WELCOME TO THE ATTORNEY ACADEMY ON REASONABLE EFFORTS
          </h3>
          <p>
            In this course, you will learn how to make meaningful reasonable efforts arguments in a child welfare case. The course is composed of three parts:
          </p>
          <ul>
            <li><strong>Part 1:</strong> An online pre-workshop assessment of your current knowledge, including a learner performance report that provides answers to the questions,</li>
            <li><strong>Part 2:</strong> Two days of in-person instruction centered around interactive simulations in a live classroom environment, with experts present to help you refine your skills, and</li>
            <li><strong>Part 3:</strong> An online post-workshop assessment so you can see your improvements after the training.</li>
          </ul>
          <p>
            This pre-test assessment should take you about fifteen minutes to complete. You may take the online assessment on your computer, tablet, or phone. 
            After completing the online assessment, you will have access to a learner performance report that provides answers and explanations to the questions.
          </p>
          <p>
            Please <u>use the same email</u> address to log in and out of the online portion of the course. Using the same email insures we can link your work throughout the course so you can track your improvements. Once you have completed the pre-workshop assessment <u>do not</u> go on to complete the post-test assessment. 
            Simply log out of the course or close your browser window. You will be given time at the end of the live training to complete and review the post-workshop assessment.
          </p>
          <p>
            The online portion of the course work best on Safari, Chrome, Microsoft Edge, or Firefox.
          </p>
          <p>
            <strong>It does not work on Internet Explorer.</strong>
          </p>
        </body>
      </html>
    `
}
