///|
/// The sign of a duration or comparison.
pub(all) enum Sign {
  /// Every non-zero field is negative.
  Negative
  /// Every field is zero.
  Zero
  /// Every non-zero field is positive.
  Positive
} derive(Eq, Compare, Debug)

///|
pub impl Default for Sign with fn default() {
  Positive
}

///|
pub impl Show for Sign with fn output(self, logger) {
  logger.write_string(self.to_int().to_string())
}

///|
/// Returns `-1`, `0` or `1`.
pub fn Sign::to_int(self : Sign) -> Int {
  match self {
    Negative => -1
    Zero => 0
    Positive => 1
  }
}

///|
/// Builds a sign from a signed number's sign.
pub fn Sign::of_int(value : Int) -> Sign {
  if value < 0 {
    Negative
  } else if value > 0 {
    Positive
  } else {
    Zero
  }
}

///|
/// Builds a sign from a signed number's sign.
pub fn Sign::of_int64(value : Int64) -> Sign {
  if value < 0L {
    Negative
  } else if value > 0L {
    Positive
  } else {
    Zero
  }
}

///|
/// Returns `1` for a zero sign, so that multiplying by the result never
/// annihilates a value. This is `temporal_rs`'s `as_sign_multiplier`.
pub fn Sign::to_multiplier(self : Sign) -> Int {
  match self {
    Zero | Positive => 1
    Negative => -1
  }
}

///|
/// Flips the sign; zero stays zero.
pub fn Sign::negate(self : Sign) -> Sign {
  match self {
    Negative => Positive
    Zero => Zero
    Positive => Negative
  }
}