use serde::{Deserialize, Serialize};

use crate::inspect::smp::services::{
    SmpPeriodicTriLaneSaveShapeFamilyCandidateSummaryEntry, SmpServiceConsumerHypothesis,
    SmpServiceTraceBranchStatus,
};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpPeriodicCompanyServiceTraceEntry {
    pub company_id: u32,
    pub name: String,
    pub active: bool,
    #[serde(default)]
    pub linked_chairman_profile_id: Option<u32>,
    pub preferred_locomotive_engine_type_raw_u8: u8,
    pub city_connection_latch: bool,
    pub linked_transit_latch: bool,
    pub linked_transit_autoroute_site_score_cache_refresh_absolute_counter: u32,
    pub linked_transit_site_peer_cache_refresh_absolute_counter: u32,
    #[serde(default)]
    pub branches: Vec<SmpServiceTraceBranchStatus>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructureProfilePayloadSummaryEntry {
    pub profile_payload_dword_hex: String,
    pub profile_status_kind: String,
    pub count: usize,
    #[serde(default)]
    pub sample_primary_names: Vec<String>,
    #[serde(default)]
    pub sample_secondary_names: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructureProfilePayloadDeltaSummaryEntry {
    pub delta_hex: String,
    pub count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructureProfileFooterPaddingSummaryEntry {
    pub padding_len: usize,
    pub count: usize,
    #[serde(default)]
    pub sample_hex_bytes: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructureProfileCompanionByteSummaryEntry {
    pub companion_byte_hex: String,
    pub count: usize,
    #[serde(default)]
    pub sample_primary_names: Vec<String>,
    #[serde(default)]
    pub sample_secondary_names: Vec<String>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructureNonzeroCompanionNamePairSummaryEntry {
    pub companion_byte_hex: String,
    pub primary_name: String,
    pub secondary_name: String,
    pub count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructureNonzeroCompanionBuildingFamilyOverlapSummaryEntry {
    pub companion_byte_hex: String,
    pub primary_name: String,
    pub secondary_name: String,
    pub count: usize,
    pub primary_matches_nonzero_stock_building_header_family: bool,
    pub secondary_matches_nonzero_stock_building_header_family: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructureNonzeroCompanionBuildingFamilyResidueSummaryEntry {
    pub companion_byte_hex: String,
    pub primary_name: String,
    pub secondary_name: String,
    pub count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpSavePlacedStructurePolicyTrailingWordSummaryEntry {
    pub policy_trailing_word_hex: String,
    pub count: usize,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SmpPeriodicCompanyServiceTraceReport {
    pub profile_family: String,
    #[serde(default)]
    pub selected_company_id: Option<u32>,
    #[serde(default)]
    pub world_issue_37_present: bool,
    #[serde(default)]
    pub world_finance_neighborhood_present: bool,
    #[serde(default)]
    pub region_record_body_present: bool,
    #[serde(default)]
    pub placed_structure_record_body_present: bool,
    #[serde(default)]
    pub infrastructure_asset_side_buffer_present: bool,
    pub peer_site_selector_candidate_owner_strip: String,
    pub peer_site_selector_candidate_persisted_tag_hex: String,
    pub peer_site_selector_candidate_selector_lane: String,
    pub peer_site_selector_candidate_secondary_payload_lane: String,
    pub peer_site_selector_candidate_post_secondary_byte_status: String,
    pub peer_site_selector_candidate_class_identity_status: String,
    #[serde(default)]
    pub peer_site_selector_candidate_helper_linkage: Vec<String>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_payload_summaries:
        Vec<SmpSavePlacedStructureProfilePayloadSummaryEntry>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_payload_delta_summaries:
        Vec<SmpSavePlacedStructureProfilePayloadDeltaSummaryEntry>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_footer_padding_summaries:
        Vec<SmpSavePlacedStructureProfileFooterPaddingSummaryEntry>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_companion_byte_summaries:
        Vec<SmpSavePlacedStructureProfileCompanionByteSummaryEntry>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_policy_trailing_word_summaries:
        Vec<SmpSavePlacedStructurePolicyTrailingWordSummaryEntry>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_nonzero_companion_name_pair_summaries:
        Vec<SmpSavePlacedStructureNonzeroCompanionNamePairSummaryEntry>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_nonzero_companion_building_family_overlap_summaries:
        Vec<SmpSavePlacedStructureNonzeroCompanionBuildingFamilyOverlapSummaryEntry>,
    #[serde(default)]
    pub peer_site_selector_candidate_saved_nonzero_companion_building_family_residue_summaries:
        Vec<SmpSavePlacedStructureNonzeroCompanionBuildingFamilyResidueSummaryEntry>,
    #[serde(default)]
    pub peer_site_persisted_selector_bundle_fields: Vec<String>,
    #[serde(default)]
    pub peer_site_rebuilt_transient_followon_fields: Vec<String>,
    pub peer_site_shellless_minimum_persisted_identity_status: String,
    #[serde(default)]
    pub peer_site_shellless_minimum_persisted_identity_inputs: Vec<String>,
    #[serde(default)]
    pub peer_site_restore_input_fields: Vec<String>,
    #[serde(default)]
    pub peer_site_runtime_input_fields: Vec<String>,
    pub peer_site_runtime_reconstruction_status: String,
    #[serde(default)]
    pub peer_site_runtime_reconstruction_steps: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_region_input_fields: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_peer_input_fields: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_company_input_fields: Vec<String>,
    pub near_city_acquisition_shellless_readiness_status: String,
    #[serde(default)]
    pub near_city_acquisition_runtime_backed_input_families: Vec<String>,
    pub near_city_acquisition_site_owner_company_projection_status: String,
    pub near_city_acquisition_site_self_id_projection_status: String,
    pub near_city_acquisition_site_cached_tri_lane_projection_status: String,
    pub near_city_acquisition_tri_lane_live_service_status: String,
    pub near_city_acquisition_candidate_subtype_projection_status: String,
    pub near_city_acquisition_backing_record_projection_status: String,
    pub near_city_acquisition_nontransport_persisted_source_status: String,
    #[serde(default)]
    pub near_city_acquisition_nontransport_persisted_source_candidates: Vec<String>,
    pub near_city_acquisition_tri_lane_save_shape_family_status: String,
    #[serde(default)]
    pub near_city_acquisition_tri_lane_save_shape_family_candidates:
        Vec<SmpPeriodicTriLaneSaveShapeFamilyCandidateSummaryEntry>,
    #[serde(default)]
    pub near_city_acquisition_tri_lane_live_owner_families: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_tri_lane_candidate_gate_fields: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_tri_lane_runtime_writer_roles: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_tri_lane_direct_caller_families: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_tri_lane_formula_input_lanes: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_projection_hypotheses: Vec<SmpServiceConsumerHypothesis>,
    #[serde(default)]
    pub near_city_acquisition_remaining_owner_gaps: Vec<String>,
    #[serde(default)]
    pub near_city_acquisition_region_lane_statuses: Vec<String>,
    #[serde(default)]
    pub atlas_candidate_consumers: Vec<String>,
    #[serde(default)]
    pub known_bridge_helpers: Vec<String>,
    #[serde(default)]
    pub next_owner_questions: Vec<String>,
    pub linked_transit_shellless_readiness_status: String,
    #[serde(default)]
    pub linked_transit_minimum_persisted_identity_inputs: Vec<String>,
    #[serde(default)]
    pub linked_transit_live_rebuilt_cache_lanes: Vec<String>,
    #[serde(default)]
    pub linked_transit_runtime_backed_input_families: Vec<String>,
    #[serde(default)]
    pub linked_transit_remaining_owner_gaps: Vec<String>,
    #[serde(default)]
    pub companies: Vec<SmpPeriodicCompanyServiceTraceEntry>,
    #[serde(default)]
    pub notes: Vec<String>,
}
