use super::atlas::build_region_atlas_fields;
use super::entries::build_region_service_trace_entries;
use super::hypotheses::build_region_service_hypotheses;
use super::notes::build_region_service_trace_notes;
use crate::inspect::smp::services::SmpRegionServiceTraceReport;
use crate::inspect::smp::world::SmpSaveCompanyChairmanAnalysisReport;

pub(in crate::inspect::smp) fn build_region_service_trace_report(
    analysis: &SmpSaveCompanyChairmanAnalysisReport,
) -> SmpRegionServiceTraceReport {
    let atlas = build_region_atlas_fields();
    let candidate_consumer_hypotheses = build_region_service_hypotheses(analysis);
    let entries = build_region_service_trace_entries(analysis);
    let notes = build_region_service_trace_notes(analysis);
    SmpRegionServiceTraceReport {
        profile_family: analysis.profile_family.clone(),
        region_collection_header_present: analysis.region_collection_header.is_some(),
        region_record_triplet_count: analysis
            .region_record_triplets
            .as_ref()
            .map(|probe| probe.record_count)
            .unwrap_or_default(),
        queued_notice_record_count: analysis
            .region_queued_notice_records
            .as_ref()
            .map(|probe| probe.entries.len())
            .unwrap_or_default(),
        atlas_candidate_consumers: atlas.atlas_candidate_consumers,
        known_owner_bridge_fields: atlas.known_owner_bridge_fields,
        known_bridge_helpers: atlas.known_bridge_helpers,
        next_owner_questions: atlas.next_owner_questions,
        candidate_consumer_hypotheses,
        entries,
        notes,
    }
}
