use crate::inspect::smp::services::*;

pub(super) struct NearCityTriLaneFields {
    pub(super) near_city_acquisition_tri_lane_save_shape_family_status: String,
    pub(super) near_city_acquisition_tri_lane_save_shape_family_candidates:
        Vec<SmpPeriodicTriLaneSaveShapeFamilyCandidateSummaryEntry>,
    pub(super) near_city_acquisition_tri_lane_live_owner_families: Vec<String>,
    pub(super) near_city_acquisition_tri_lane_candidate_gate_fields: Vec<String>,
    pub(super) near_city_acquisition_tri_lane_runtime_writer_roles: Vec<String>,
    pub(super) near_city_acquisition_tri_lane_direct_caller_families: Vec<String>,
    pub(super) near_city_acquisition_tri_lane_formula_input_lanes: Vec<String>,
}

pub(super) fn build_near_city_tri_lane_fields(
    analysis: &SmpSaveCompanyChairmanAnalysisReport,
) -> NearCityTriLaneFields {
    let near_city_acquisition_tri_lane_save_shape_family_candidates =
        summarize_near_city_acquisition_tri_lane_save_shape_family_candidates(analysis);
    let near_city_acquisition_tri_lane_save_shape_family_status =
        if near_city_acquisition_tri_lane_save_shape_family_candidates.is_empty() {
            "save_shape_family_probe_missing".to_string()
        } else {
            "save_shape_family_candidates_present_fixed_offset_ruled_down".to_string()
        };

    NearCityTriLaneFields {
        near_city_acquisition_tri_lane_save_shape_family_status,
        near_city_acquisition_tri_lane_save_shape_family_candidates,
        near_city_acquisition_tri_lane_live_owner_families: vec![
            "0x0040d450 owner-company-aware local scorer producing [site+0x310]".to_string(),
            "0x00410b30..0x004118f4 broader candidate-processing loop producing [site+0x310/+0x338/+0x360]"
                .to_string(),
            "0x00412560 shared candidate/admissibility gate above both scorer paths"
                .to_string(),
            "0x0040c9a0 deferred additive accumulator/reset folding the tri-lane into [site+0x2b4/+0x2b8/+0x2bc] and [site+0x2e4..]"
                .to_string(),
            "0x0040fcc0..0x0040fe28 and 0x00422c62..0x00422d3c weighted scoring/evaluation consumers reading 0x0040cac0"
                .to_string(),
        ],
        near_city_acquisition_tri_lane_candidate_gate_fields: vec![
            "0x00412560 gates candidate rows using fields [+0x20/+0x22/+0x24/+0x28/+0x2c/+0x44]"
                .to_string(),
            "0x00412560 consumes world date/flags through 0x006cec78".to_string(),
            "0x00412560 resolves candidate rows from table 0x0062ba8c".to_string(),
            "0x00412560 callers pass the placed-structure subject vtable slot +0x80 result plus owner-present flag from [site+0x246]"
                .to_string(),
            "direct callers of 0x00412560 are now bounded at 0x0040fb8d, 0x00410721, 0x00410b71, 0x00412620, and 0x004126d3"
                .to_string(),
        ],
        near_city_acquisition_tri_lane_runtime_writer_roles: vec![
            "0x0040d450 adds one owner-company-aware local score component into [site+0x310]"
                .to_string(),
            "0x00410b30..0x004118f4 walks 0xbc-stride candidate rows and adds per-row score components into [site+0x310/+0x338/+0x360]"
                .to_string(),
            "0x0041114a7/0x004111572 add into [site+0x310] and 0x0041114b7/0x004111582 add into [site+0x338]"
                .to_string(),
            "0x0041118aa/0x0041118f4 add into [site+0x360]".to_string(),
            "0x0040c9a0 later folds the tri-lane into [site+0x2b4/+0x2b8/+0x2bc] and clears the transient producer lanes"
                .to_string(),
        ],
        near_city_acquisition_tri_lane_direct_caller_families: vec![
            "0x0040fb70 is a small wrapper passing one candidate row plus the subject vtable slot +0x80 result and owner-present flag into 0x00412560"
                .to_string(),
            "0x004b4052 / 0x004b46ec are collection-wide 0x0040fb70 callers iterating 0x0062b26c candidate rows"
                .to_string(),
            "0x00401633 is an acquisition-adjacent 0x0040d540 caller that immediately feeds company stat-family 0x2329/0x0d"
                .to_string(),
            "0x0044b81a is an owner-company-aware 0x0040d540 caller that also reaches 0x0040cb70 and 0x00436590 news/event id 0x65"
                .to_string(),
            "0x004b70f5 / 0x004b7979 are broader 0x0040d540 callers routing through 0x004337a0 and downstream 0x00540120 / 0x00518140 state consumers"
                .to_string(),
        ],
        near_city_acquisition_tri_lane_formula_input_lanes: vec![
            "0x00412560 uses candidate-row time window [+0x20/+0x22], owner/absence booleans [+0x24/+0x28], list count [+0x2c], and membership list [+0x44]"
                .to_string(),
            "0x00412560 consumes world date and policy flags through 0x006cec78 fields [world+0x0d] and [world+0x4afb]"
                .to_string(),
            "0x0040d450 combines helper outputs 0x00455810 / 0x00455800 / 0x0044ad60 with owner-company lane [site+0x276] and world event sink 0x00436590 ids 0x66/0x68"
                .to_string(),
            "0x00410b30..0x004118f4 consumes candidate-row fields [+0x18/+0x1c/+0x2a/+0x2c/+0x44], subject latch [site+0x78c], and personality byte [site+0x391]"
                .to_string(),
            "0x00410b30..0x004118f4 also feeds world-side scalar [world+0x4caa], owner-company scalar [company+0x0d5d] through 0x0040d210, and the local cache bands [site+0x2e8], [site+0x310], [site+0x338], and [site+0x360]"
                .to_string(),
        ],
    }
}
