use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum RuntimeCompanyControllerKind {
    #[default]
    Unknown,
    Human,
    Ai,
}

fn runtime_company_default_active() -> bool {
    true
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RuntimeCompany {
    pub company_id: u32,
    pub current_cash: i64,
    pub debt: u64,
    #[serde(default)]
    pub credit_rating_score: Option<i64>,
    #[serde(default)]
    pub prime_rate: Option<i64>,
    #[serde(default = "runtime_company_default_active")]
    pub active: bool,
    #[serde(default)]
    pub available_track_laying_capacity: Option<u32>,
    #[serde(default)]
    pub controller_kind: RuntimeCompanyControllerKind,
    #[serde(default)]
    pub linked_chairman_profile_id: Option<u32>,
    #[serde(default)]
    pub book_value_per_share: i64,
    #[serde(default)]
    pub investor_confidence: i64,
    #[serde(default)]
    pub management_attitude: i64,
    #[serde(default)]
    pub takeover_cooldown_year: Option<u32>,
    #[serde(default)]
    pub merger_cooldown_year: Option<u32>,
    #[serde(default)]
    pub track_piece_counts: RuntimeTrackPieceCounts,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct RuntimeTrackPieceCounts {
    #[serde(default)]
    pub total: u32,
    #[serde(default)]
    pub single: u32,
    #[serde(default)]
    pub double: u32,
    #[serde(default)]
    pub transition: u32,
    #[serde(default)]
    pub electric: u32,
    #[serde(default)]
    pub non_electric: u32,
}
