use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

use crate::event::news::{RuntimeAnnualFinanceNewsEvent, RuntimeNearCityAcquisitionNewsEvent};
use crate::state::{
    RuntimeCompanyAnnualFinancePolicyAction, RuntimeCompanyMarketState,
    RuntimeCompanyPeriodicSideLatchState, RuntimeNearCityAcquisitionRegion,
    RuntimeNearCityAcquisitionSite, RuntimeWorldRoutePreferenceOverrideState,
};

#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
pub struct RuntimeServiceState {
    #[serde(default)]
    pub periodic_boundary_calls: u64,
    #[serde(default)]
    pub annual_finance_service_calls: u64,
    #[serde(default)]
    pub periodic_route_preference_override_apply_count: u64,
    #[serde(default)]
    pub periodic_route_preference_override_restore_count: u64,
    #[serde(default)]
    pub trigger_dispatch_counts: BTreeMap<u8, u64>,
    #[serde(default)]
    pub total_event_record_services: u64,
    #[serde(default)]
    pub dirty_rerun_count: u64,
    #[serde(default)]
    pub world_issue_opinion_base_terms_raw_i32: Vec<i32>,
    #[serde(default)]
    pub company_market_state: BTreeMap<u32, RuntimeCompanyMarketState>,
    #[serde(default)]
    pub company_periodic_side_latch_state: BTreeMap<u32, RuntimeCompanyPeriodicSideLatchState>,
    #[serde(default)]
    pub active_periodic_route_preference_override: Option<RuntimeWorldRoutePreferenceOverrideState>,
    #[serde(default)]
    pub last_periodic_route_preference_override: Option<RuntimeWorldRoutePreferenceOverrideState>,
    #[serde(default)]
    pub annual_finance_last_actions: BTreeMap<u32, RuntimeCompanyAnnualFinancePolicyAction>,
    #[serde(default)]
    pub annual_finance_action_counts: BTreeMap<RuntimeCompanyAnnualFinancePolicyAction, u64>,
    #[serde(default)]
    pub annual_dividend_adjustment_commit_count: u64,
    #[serde(default)]
    pub annual_bond_last_retired_principal_total: u64,
    #[serde(default)]
    pub annual_bond_last_issued_principal_total: u64,
    #[serde(default)]
    pub annual_stock_repurchase_last_share_count: u64,
    #[serde(default)]
    pub annual_stock_issue_last_share_count: u64,
    #[serde(default)]
    pub annual_finance_last_news_family_candidates: BTreeMap<u32, String>,
    #[serde(default)]
    pub annual_finance_last_news_events: Vec<RuntimeAnnualFinanceNewsEvent>,
    #[serde(default)]
    pub near_city_acquisition_regions: Vec<RuntimeNearCityAcquisitionRegion>,
    #[serde(default)]
    pub near_city_acquisition_sites: Vec<RuntimeNearCityAcquisitionSite>,
    #[serde(default)]
    pub near_city_acquisition_service_calls: u64,
    #[serde(default)]
    pub near_city_acquisition_last_news_family_candidates: BTreeMap<u32, String>,
    #[serde(default)]
    pub near_city_acquisition_last_news_events: Vec<RuntimeNearCityAcquisitionNewsEvent>,
    #[serde(default)]
    pub chairman_issue_opinion_terms_raw_i32: BTreeMap<u32, Vec<i32>>,
    #[serde(default)]
    pub chairman_personality_raw_u8: BTreeMap<u32, u8>,
}
