/**
 * The guardian block's five fields, and the rule for what to send when the
 * registrant is not a minor.
 *
 * The block only renders under 18 — every call site wraps it in that test —
 * but the values live in the same Formik bag as the rest of the form and every
 * registration payload is built by spreading that bag. Before the dial-code
 * default moved into the initial values (see `DEFAULT_DIAL_CODE`) an adult
 * registrant therefore sent five empty strings, because nothing had ever
 * written to the fields. With a default in place the dial code would be the
 * one key that arrived populated for a contact who does not exist, so the
 * clearing that was previously implicit is now stated.
 *
 * `""` rather than dropping the keys: `RegisterRequest` marks all five
 * `nullable` and requires them only under 18, and the existing profile save
 * (`useVolunteerAccountSubmit`) already sends `""` for an adult — matching it
 * keeps one meaning of "no guardian" on the wire.
 */
export const EMERGENCY_CONTACT_FIELDS = [
  "emergency_contact_name",
  "emergency_contact_phone",
  "emergency_contact_country_code",
  "emergency_contact_civil_id",
  "emergency_contact_relationship",
] as const;

export type EmergencyContactField = (typeof EMERGENCY_CONTACT_FIELDS)[number];

export type EmergencyContactValues = Record<EmergencyContactField, string>;

/**
 * The five keys as they should appear in a registration body: the organizer's
 * answers for a minor, blanks for anyone else.
 *
 * Spread over the form values, so a caller cannot forget one of the five.
 */
export function emergencyContactPayload(
  values: EmergencyContactValues,
  isMinor: boolean
): EmergencyContactValues {
  const payload = {} as EmergencyContactValues;
  for (const field of EMERGENCY_CONTACT_FIELDS) {
    payload[field] = isMinor ? (values[field] ?? "") : "";
  }
  return payload;
}
