/**
 * Builds the EoE Patient Perspectives survey as a Google Form, anonymously configured.
 *
 * HOW TO RUN (2 minutes):
 *   1. Go to https://script.google.com  ->  New project
 *   2. Delete the placeholder code, paste this whole file, click Save.
 *   3. Click Run (the play button). Approve the permission prompt the first time.
 *   4. Open the Execution log — it prints the live form URL and the edit URL.
 *
 * The script turns OFF email collection and one-response-per-user, so responses
 * are anonymous and no Google sign-in is forced.
 */
function buildEoEForm() {
  var form = FormApp.create('EoE Patient Perspectives — Short Survey');

  form.setDescription(
    "Thanks for helping! This is a short (~5 minute), completely ANONYMOUS survey about living with " +
    "eosinophilic esophagitis (EoE) and how you feel about current and future treatments. Your answers " +
    "will help shape a research idea for a new kind of EoE therapy.\n\n" +
    "• Participation is voluntary — skip any question you'd rather not answer.\n" +
    "• No names, emails, or identifying information are collected.\n" +
    "• This is an informal survey, NOT a research study or medical advice, and nothing here changes your care. " +
    "For any medical decisions, talk to your own doctor.\n\n" +
    "By continuing, you're agreeing to take part. Thank you!"
  );

  // --- Anonymity / friction settings ---
  form.setCollectEmail(false);            // no email addresses stored
  form.setLimitOneResponsePerUser(false); // no forced Google sign-in
  form.setAllowResponseEdits(false);
  form.setProgressBar(true);
  form.setShowLinkToRespondAgain(false);

  // ---------- Section 1: context ----------
  form.addSectionHeaderItem().setTitle('A little context');

  form.addMultipleChoiceItem()
    .setTitle('How long ago were you diagnosed with EoE?')
    .setChoiceValues(['Less than 1 year','1–3 years','3–5 years','5–10 years','More than 10 years']);

  form.addCheckboxItem()
    .setTitle('How is your EoE currently managed? (select all that apply)')
    .setChoiceValues([
      'Proton-pump inhibitors (e.g., omeprazole)',
      'Swallowed / topical steroids (e.g., budesonide, fluticasone)',
      'Dietary elimination (e.g., dairy-free, 6-food elimination)',
      'A biologic injection (e.g., dupilumab / Dupixent)',
      'Esophageal dilation procedures',
      'No treatment right now',
      'Other'
    ]);

  form.addCheckboxItem()
    .setTitle('Do you know or suspect specific food triggers? (select all that apply)')
    .setChoiceValues([
      'Milk / dairy','Wheat / gluten','Egg','Soy','Nuts','Fish / shellfish',
      'Not identified / unknown','Other'
    ]);

  // ---------- Section 2: burden today ----------
  form.addSectionHeaderItem().setTitle('Living with EoE today');

  form.addScaleItem()
    .setTitle('Overall, how much does managing EoE interfere with your daily life?')
    .setBounds(1,5).setLabels('Not at all','A great deal');

  var q5 = form.addCheckboxItem();
  q5.setTitle('Which parts of managing EoE are most burdensome for you? (select up to 3)')
    .setChoiceValues([
      'Restricting or avoiding foods',
      'Taking daily medication',
      'Repeat endoscopies / biopsies',
      'Cost / insurance',
      'Symptom flares (trouble swallowing, food getting stuck, pain)',
      'Food-related anxiety or social impact',
      'Other'
    ])
    .setValidation(FormApp.createCheckboxValidation().requireSelectAtMost(3).build());

  form.addScaleItem()
    .setTitle('How satisfied are you with your current treatment options?')
    .setBounds(1,5).setLabels('Very dissatisfied','Very satisfied');

  // ---------- Section 3: new treatment ----------
  form.addSectionHeaderItem()
    .setTitle('A new kind of treatment')
    .setHelpText(
      "Researchers are exploring treatments that would gently retrain your immune system to TOLERATE the " +
      "foods that trigger EoE — the goal being fewer symptoms and less need for lifelong diet restriction " +
      "or daily medication. The next questions ask how you'd feel about an approach like this."
    );

  form.addScaleItem()
    .setTitle('How interested would you be in a treatment that retrains your immune system to tolerate your trigger foods?')
    .setBounds(1,5).setLabels('Not at all interested','Extremely interested');

  form.addMultipleChoiceItem()
    .setTitle('Would you be open to receiving such a treatment as an injection or short series of injections?')
    .setChoiceValues(['Yes','Maybe / depends','No']);

  var q9 = form.addCheckboxItem();
  q9.setTitle('What would most influence your decision to try a new immune-based treatment? (select up to 3)')
    .setChoiceValues([
      'Safety / side effects',
      'How well it works',
      'Being able to eat trigger foods again',
      'Reducing or stopping daily medication',
      'Fewer endoscopies / procedures',
      "My doctor's recommendation",
      'Cost / insurance coverage',
      'Other'
    ])
    .setValidation(FormApp.createCheckboxValidation().requireSelectAtMost(3).build());

  form.addMultipleChoiceItem()
    .setTitle('If a new treatment worked well, which outcome would matter most to you? (pick one)')
    .setChoiceValues([
      'Being able to eat foods I currently avoid',
      'Stopping daily medication',
      'Fewer endoscopies / procedures',
      'Fewer symptoms and flares',
      'Less anxiety around food',
      'Other'
    ]);

  // ---------- Section 4: open text ----------
  form.addSectionHeaderItem().setTitle('In your words (optional)');

  form.addParagraphTextItem()
    .setTitle('In a sentence or two: what would an ideal EoE treatment do for you that your current options don\'t?');

  // ---------- Optional demographic ----------
  form.addMultipleChoiceItem()
    .setTitle('Age range (optional)')
    .setChoiceValues(['Under 18','18–29','30–44','45–59','60+','Prefer not to say']);

  Logger.log('LIVE FORM (share this):  ' + form.getPublishedUrl());
  Logger.log('EDIT FORM (yours only):  ' + form.getEditUrl());
}
