
function updateStaffDispositionDropdowns() {

  // Open the existing Staff Disposition Google Form
  const form = FormApp.openById(
    "18lTnzuR5thUS4KCpLI4jzXcw2MfmT-lsfhsJz7bULaU"
  );

  // Nigerian States and FCT
  const states = [
    "Abia", "Adamawa", "Akwa Ibom", "Anambra", "Bauchi",
    "Bayelsa", "Benue", "Borno", "Cross River", "Delta",
    "Ebonyi", "Edo", "Ekiti", "Enugu", "Gombe", "Imo",
    "Jigawa", "Kaduna", "Kano", "Katsina", "Kebbi",
    "Kogi", "Kwara", "Lagos", "Nasarawa", "Niger",
    "Ogun", "Ondo", "Osun", "Oyo", "Plateau", "Rivers",
    "Sokoto", "Taraba", "Yobe", "Zamfara",
    "Federal Capital Territory (FCT)"
  ];

  // Lagos State 20 Local Government Areas and 37 LCDAs
  const locations = [
    "Agege", "Ajeromi-Ifelodun", "Alimosho", "Amuwo-Odofin",
    "Apapa", "Badagry", "Epe", "Eti-Osa", "Ibeju-Lekki",
    "Ifako-Ijaiye", "Ikeja", "Ikorodu", "Kosofe",
    "Lagos Island", "Lagos Mainland", "Mushin",
    "Ojo", "Oshodi-Isolo", "Shomolu", "Surulere",

    "Agbado/Oke-Odo", "Agboyi-Ketu", "Apapa-Iganmu",
    "Ayobo-Ipaja", "Badagry West", "Bariga", "Bayeku",
    "Ejigbo", "Eredo", "Ikosi-Ejirin", "Ikosi-Isheri",
    "Ikorodu North", "Ikorodu West", "Igbogbo-Baiyeku",
    "Imota", "Isolo", "Itire-Ikate", "Iru/Victoria Island",
    "Lekki", "Mafoluku", "Mosan-Okunola",
    "Odi-Olowo/Ojuwoye", "Ojodu", "Ojokoro",
    "Olorunda", "Onigbongbo", "Orile-Agege",
    "Oto-Awori"
  ];

  // Grade Levels
  const gradeLevels = [];
  for (let i = 1; i <= 17; i++) {
    gradeLevels.push("GL " + String(i).padStart(2, "0"));
  }

  // Educational Qualifications
  const qualifications = [
    "Primary School Certificate",
    "FSLC",
    "WASC / WAEC / NECO / GCE",
    "OND",
    "NCE",
    "HND",
    "Bachelor's Degree (B.Sc / B.A / B.Ed)",
    "Postgraduate Diploma (PGD)",
    "Master's Degree (M.Sc / M.A / MBA / M.Ed)",
    "Doctorate Degree (Ph.D)",
    "Professional Qualification",
    "Other"
  ];

  // Cadre options - confirm these against the Commission's
  // approved cadre register before distributing the form.
  const cadres = [
    "Administrative",
    "Account",
    "Audit",
    "Education",
    "Engineering",
    "Health",
    "Information",
    "Legal",
    "Planning, Research and Statistics",
    "Social Welfare",
    "Other"
  ];

  // Designation options - editable to match the Commission's
  // approved staff designation register.
  const designations = [
    "Administrative Officer",
    "Accountant",
    "Auditor",
    "Chief Administrative Officer",
    "Chief Accountant",
    "Chief Auditor",
    "Chief Executive Officer",
    "Chief Programme Analyst",
    "Computer Analyst",
    "Data Processing Officer",
    "Education Officer",
    "Engineer",
    "Executive Officer",
    "Higher Executive Officer",
    "Human Resources Officer",
    "Internal Auditor",
    "Legal Officer",
    "Librarian",
    "Medical Officer",
    "Personnel Officer",
    "Planning Officer",
    "Programme Analyst",
    "Secretarial Assistant",
    "Senior Administrative Officer",
    "Senior Accountant",
    "Senior Executive Officer",
    "Senior Personnel Officer",
    "Technical Officer",
    "Other"
  ];

  // Update an existing question to a dropdown list.
  // If already a dropdown, only update its choices.
  // If it is a text question, replace it at the same position.
  function makeDropdown(questionTitle, choices) {

    const items = form.getItems();

    let existingItem = null;
    let oldPosition = items.length;

    for (let i = 0; i < items.length; i++) {
      if (items[i].getTitle() === questionTitle) {
        existingItem = items[i];
        oldPosition = i;
        break;
      }
    }

    if (existingItem) {

      if (existingItem.getType() === FormApp.ItemType.LIST) {
        existingItem.asListItem().setChoiceValues(choices);
        existingItem.asListItem().setRequired(true);
        return;
      }

      form.deleteItem(existingItem);
    }

    const newItem = form.addListItem();
    newItem.setTitle(questionTitle);
    newItem.setChoiceValues(choices);
    newItem.setRequired(true);

    // No need to move the question.
  }

  // Apply all six dropdowns
  makeDropdown("PRESENT POST / DESIGNATION", designations);
  makeDropdown("CADRE", cadres);
  makeDropdown("STATE OF ORIGIN", states);
  makeDropdown("GRADE LEVEL", gradeLevels);
  makeDropdown("EDUCATIONAL QUALIFICATION", qualifications);
  makeDropdown("PRESENT LGA / LCDA", locations);

  Logger.log("SUCCESS: All six dropdown fields have been updated.");
  Logger.log("FORM LINK: " + form.getPublishedUrl());

}
