// variables tracked both in CP and Firestore

// Below is current course data...we build old version
// data on the fly for CSV in `versionedCourseData()` function
const COURSE_DATA = {
  academy: null,
  PreAacademyComplete: 0,
  PostAacademyComplete: 0,
  PreAacademyQ1A1: null,
  PreAacademyQ1A2: null,
  PreAacademyQ1A3: null,
  PreAacademyQ1A4: null,
  PreAacademyCheckQ1: null,
  PreAacademyQ2A1: null,
  PreAacademyQ2A2: null,
  PreAacademyQ2A3: null,
  PreAacademyQ2A4: null,
  PreAacademyCheckQ2: null,
  PreAacademyQ3A1: null,
  PreAacademyQ3A2: null,
  PreAacademyQ3A3: null,
  PreAacademyQ3A4: null,
  PreAacademyQ3A5: null,
  PreAacademyCheckQ3: null,
  PreAacademyQ4A1: null,
  PreAacademyQ4A2: null,
  PreAacademyQ4A3: null,
  PreAacademyQ4A4: null,
  PreAacademyQ4A5: null,
  PreAacademyCheckQ4: null,
  PreAacademyQ5A1: null,
  PreAacademyQ5A2: null,
  PreAacademyQ5A3: null,
  PreAacademyQ5A4: null,
  PreAacademyQ5A5: null,
  PreAacademyCheckQ5: null,
  PreAacademyQ6A1: null,
  PreAacademyQ6A2: null,
  PreAacademyQ6A3: null,
  PreAacademyQ6A4: null,
  PreAacademyCheckQ6: null,
  PreAacademyQ7A1: null,
  PreAacademyQ7A2: null,
  PreAacademyQ7A3: null,
  PreAacademyQ7A4: null,
  PreAacademyQ7A5: null,
  PreAacademyCheckQ7: null,
  PreAacademyQ8A1: null,
  PreAacademyQ8A2: null,
  PreAacademyQ8A3: null,
  PreAacademyQ8A4: null,
  PreAacademyQ8A5: null,
  PreAacademyCheckQ8: null,
  PreAacademyQ9A1: null,
  PreAacademyQ9A2: null,
  PreAacademyQ9A3: null,
  PreAacademyQ9A4: null,
  PreAacademyQ9A5: null,
  PreAacademyCheckQ9: null,
  PreAacademyQ10A1: null,
  PreAacademyQ10A2: null,
  PreAacademyQ10A3: null,
  PreAacademyQ10A4: null,
  PreAacademyCheckQ10: null,
  PreAacademyQ11A1: null,
  PreAacademyQ11A2: null,
  PreAacademyQ11A3: null,
  PreAacademyQ11A4: null,
  PreAacademyCheckQ11: null,
  PreAacademyQ12A1: null,
  PreAacademyQ12A2: null,
  PreAacademyQ12A3: null,
  PreAacademyQ12A4: null,
  PreAacademyQ12A5: null,
  PreAacademyCheckQ12: null,
  PreAacademyQ13Form: null,
  PreAacademyQ14Form: null,
  PreAacademyQ15Form: null,
  PostAacademyQ1A1: null,
  PostAacademyQ1A2: null,
  PostAacademyQ1A3: null,
  PostAacademyQ1A4: null,
  PostAacademyCheckQ1: null,
  PostAacademyQ2A1: null,
  PostAacademyQ2A2: null,
  PostAacademyQ2A3: null,
  PostAacademyQ2A4: null,
  PostAacademyCheckQ2: null,
  PostAacademyQ3A1: null,
  PostAacademyQ3A2: null,
  PostAacademyQ3A3: null,
  PostAacademyQ3A4: null,
  PostAacademyQ3A5: null,
  PostAacademyCheckQ3: null,
  PostAacademyQ4A1: null,
  PostAacademyQ4A2: null,
  PostAacademyQ4A3: null,
  PostAacademyQ4A4: null,
  PostAacademyQ4A5: null,
  PostAacademyCheckQ4: null,
  PostAacademyQ5A1: null,
  PostAacademyQ5A2: null,
  PostAacademyQ5A3: null,
  PostAacademyQ5A4: null,
  PostAacademyQ5A5: null,
  PostAacademyCheckQ5: null,
  PostAacademyQ6A1: null,
  PostAacademyQ6A2: null,
  PostAacademyQ6A3: null,
  PostAacademyQ6A4: null,
  PostAacademyCheckQ6: null,
  PostAacademyQ7A1: null,
  PostAacademyQ7A2: null,
  PostAacademyQ7A3: null,
  PostAacademyQ7A4: null,
  PostAacademyQ7A5: null,
  PostAacademyCheckQ7: null,
  PostAacademyQ8A1: null,
  PostAacademyQ8A2: null,
  PostAacademyQ8A3: null,
  PostAacademyQ8A4: null,
  PostAacademyQ8A5: null,
  PostAacademyCheckQ8: null,
  PostAacademyQ9A1: null,
  PostAacademyQ9A2: null,
  PostAacademyQ9A3: null,
  PostAacademyQ9A4: null,
  PostAacademyQ9A5: null,
  PostAacademyCheckQ9: null,
  PostAacademyQ10A1: null,
  PostAacademyQ10A2: null,
  PostAacademyQ10A3: null,
  PostAacademyQ10A4: null,
  PostAacademyCheckQ10: null,
  PostAacademyQ11A1: null,
  PostAacademyQ11A2: null,
  PostAacademyQ11A3: null,
  PostAacademyQ11A4: null,
  PostAacademyCheckQ11: null,
  PostAacademyQ12A1: null,
  PostAacademyQ12A2: null,
  PostAacademyQ12A3: null,
  PostAacademyQ12A4: null,
  PostAacademyQ12A5: null,
  PostAacademyCheckQ12: null,
  PostAacademyQ13Form: null,
  PostAacademyQ14Form: null,
  PostAacademyQ15Form: null,
  moduleVersion: '2.0'
}

// We create/sync an FS var with a CP system
// var that tracks the last slide visited. We
// can't write to this CP var so we use our FS
// 'clone' value to return a user to the last
// slide they visited.
const lastSlideFSVarNamePre = "lastSlideVisitedPre"
const lastSlideFSVarNamePost = "lastSlideVisitedPost"
const lastSlideCPVarName = "cpInfoCurrentSlide"

function userFields(email, firstAndLastName) {
  var fields = {
    "email": email,
    "firstAndLastName": firstAndLastName,
    "createdAt": firebase.firestore.Timestamp.now(),
    ...COURSE_DATA,
  }

  return fields;
}

function versionedCourseData(version) {
  let currentCourseData = { ...COURSE_DATA };

  if (version == '2.0') {
    return currentCourseData;
  }
  else {
    delete currentCourseData.PreAacademyQ4A5;
    delete currentCourseData.PostAacademyQ4A5;

    let temp = {};

    // Order matters for the columns of CSV, so we
    // insert at specific places
    for (const prop in currentCourseData) {
      temp[prop] = currentCourseData[prop];

      if (prop == 'PreAacademyQ3A5') {
        temp['PreAacademyQ3A6'] = null;
        temp['PreAacademyQ3A7'] = null;
      }
      if (prop == 'PreAacademyQ9A5') {
        temp['PreAacademyQ9A6'] = null;
      }
      if (prop == 'PostAacademyQ3A5') {
        temp['PostAacademyQ3A6'] = null;
        temp['PostAacademyQ3A7'] = null;
      }
      if (prop == 'PostAacademyQ9A5') {
        temp['PostAacademyQ9A6'] = null;
      }
    }

    return temp;
  }
}
