sota 0.7.0-rc4

API crate for Summits on the Air
Documentation
//! SOTA's raison d'ĂȘtre.

use serde::{Deserialize, Serialize};
use serde_with::{serde_as, NoneAsEmptyString};
use time::OffsetDateTime;

use crate::{Callsign, HasSummit};

/// A summit registered by a SOTA member association.
#[serde_as]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Summit {
    /// Name of the summit.
    pub name: String,
    /// Association that registered the summit, e.g. "W6".
    pub association_code: String,
    /// Name of the association, e.g. "USA".
    pub association_name: String,
    /// Full code of the summit, e.g. "W6/CC-063".
    pub summit_code: String,
    /// Region code of the summit, e.g. "CC".
    pub region_code: String,
    /// Name of the region containing the summit, e.g. "Coastal Ranges".
    pub region_name: String,
    /// Altitude in meters.
    pub alt_m: u16,
    /// Altitude in feet.
    pub alt_ft: u16,
    /// Longitude. Further meaning unknown.
    pub grid_ref_1: String,
    /// Longitude.
    pub longitude: f32,
    /// Latitude. Further meaning unknown.
    pub grid_ref_2: String,
    /// Latitude.
    pub latitude: f32,
    /// Maidenhead, e.g. "CM87qw".
    pub locator: String,
    #[serde_as(as = "NoneAsEmptyString")]
    /// Notes about the summit.
    pub notes: Option<String>,
    /// When this summit's definition took effect.
    #[serde(with = "time::serde::rfc3339")]
    pub valid_from: OffsetDateTime,
    /// When this summit's definition lost effect.
    #[serde(with = "time::serde::rfc3339")]
    pub valid_to: OffsetDateTime,
    /// Number of times the summit has been activated.
    pub activation_count: Option<u32>,
    /// Number of times the summit has been activated by the authenticated user.
    pub my_activations: Option<u32>,
    /// Number of times the summit has been chased by the authenticated user.
    pub my_chases: Option<u32>,
    /// When the summit was last activated.
    #[serde(with = "time::serde::rfc3339::option")]
    pub activation_date: Option<OffsetDateTime>,
    /// The callsign of the last activator.
    pub activation_call: Option<Callsign>,
    /// Points earned for activating or chasing the summit.
    pub points: u8,
    /// Whether the summit is currently valid.
    pub valid: bool,
    /// Restrictions currently active on the summit.
    pub restriction_list: Option<Vec<SummitRestriction>>,
    /// (This field is undocumented upstream.)
    pub restriction_mask: bool,
}

#[allow(missing_docs)] // Undocumented upstream.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct SummitRestriction {
    pub code: u16,
    #[serde(rename = "type")]
    pub ty: String,
}

impl HasSummit for Summit {
    fn summit_code(&self) -> String {
        self.summit_code.clone()
    }
}