whos_your_daddy_common 0.2.0

Common source code for the Who's Your Daddy projects, like the Enumerator and Presenter.
Documentation
//! This file contains definitions for a government official's terms in office.
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

/// Represents the level of government for an elected official.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, sqlx::Type)]
#[sqlx(type_name = "governmentlevel", rename_all = "lowercase")]
pub enum GovernmentLevel {
    /// Unknown level
    Unknown,
    /// Special districts (e.g., School Board, Water District)
    SpecialDistrict,
    /// Municipal level (e.g., Mayors, City Council Members)
    Municipal,
    /// County level (e.g., County Commissioners, Sheriffs)
    County,
    /// State level (e.g., Governor, State Legislators)
    State,
    /// Federal level (e.g., President, Senators, Representatives)
    Federal,
    /// International level (e.g., UN Secretary General)
    International,
    /// Global level
    Global,
    /// Interplanetary level
    Interplanetary,
}

impl From<()> for GovernmentLevel {
    fn from(_: ()) -> Self {
        Self::Unknown
    }
}

/// Represents the branch of government.
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, sqlx::Type)]
#[sqlx(type_name = "branch")]
pub enum Branch {
    /// Unknown branch
    Unknown,
    /// Executive branch
    Executive,
    /// Legislative branch
    Legislative,
    /// Judicial branch
    Judicial,
}

impl From<()> for Branch {
    fn from(_: ()) -> Self {
        Self::Unknown
    }
}

/// Represents a single term of office for an `Official`.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, sqlx::Type)]
pub struct Term {
    /// The branch of government that the official served in for this term.
    pub branch: Branch,

    /// Sources of information for the `branch` field.
    pub branch_sources: Vec<String>,

    /// The end date of the term in `YYYY-MM-DD` format.
    /// `None` indicates the term is ongoing.
    pub end_date: Option<NaiveDate>,

    /// Sources of information for the `end_date` field.
    pub end_date_sources: Vec<String>,

    /// The ID of this Term object.
    pub id: Uuid,

    /// The level of government for this term.
    pub level: GovernmentLevel,

    /// Sources of information for the `level` field.
    pub level_sources: Vec<String>,

    /// The location where the `Official` served during this term.
    /// (e.g., "CA", "New York City", "District 5").
    pub location: String,

    /// Sources of information for the `location` field.
    pub location_sources: Vec<String>,

    /// The title of the office held during this term.
    /// (e.g., "U.S. Senator", "Governor", "Mayor").
    pub office_title: String,

    /// Sources of information for the `office_title` field.
    pub office_title_sources: Vec<String>,

    /// Identifier of the Official or other object that owns this Term object.
    pub parent_id: Uuid,

    /// The registered political party during this term.
    /// (e.g., "Democratic", "Republican", "Independent").
    pub political_party: String,

    /// Sources of information for the `political_party` field.
    pub political_party_sources: Vec<String>,

    /// The number identifying a legislative gathering, such as the federal
    /// congress number.
    pub session_number: Option<i32>,

    /// Sources of information for the `session_number` field.
    pub session_number_sources: Vec<String>,

    /// The start date of the term in `YYYY-MM-DD` format.
    pub start_date: NaiveDate,

    /// Sources of information for the `start_date` field.
    pub start_date_sources: Vec<String>,
}