///|
/// Holds one primary phonetic key and an optional distinct alternate key.
pub(all) struct EncodedKeys {
  primary : String
  alternate : String?
} derive(Eq, Debug)

///|
/// Creates keys while removing an empty or duplicate alternate.
pub fn EncodedKeys::new(primary : String, alternate : String?) -> EncodedKeys {
  let normalized_alternate = match alternate {
    Some(value) =>
      if value.length() == 0 || value == primary {
        None
      } else {
        Some(value)
      }
    None => None
  }
  { primary, alternate: normalized_alternate }
}

///|
/// Creates an encoding with only one key.
pub fn EncodedKeys::single(primary : String) -> EncodedKeys {
  { primary, alternate: None }
}

///|
/// Returns non-empty keys in primary then alternate order.
pub fn EncodedKeys::all_non_empty_keys(self : EncodedKeys) -> Array[String] {
  let keys : Array[String] = []
  if self.primary.length() > 0 {
    keys.push(self.primary)
  }
  match self.alternate {
    Some(value) => if value.length() > 0 { keys.push(value) }
    None => ()
  }
  keys
}