use super::inputs::SelectedCompanyInputs;
use super::model::SelectedCompanySummaryFields;

pub(super) fn fill_selected_company_periodic_fields(
    fields: &mut SelectedCompanySummaryFields,
    inputs: &SelectedCompanyInputs<'_>,
) {
    fields.selected_company_periodic_side_latch_preferred_locomotive_engine_type_raw_u8 = inputs
        .periodic_side_latch_state
        .and_then(|latch_state| latch_state.preferred_locomotive_engine_type_raw_u8);
    fields.selected_company_periodic_side_latch_city_connection_latch = inputs
        .periodic_side_latch_state
        .map(|latch_state| latch_state.city_connection_latch);
    fields.selected_company_periodic_side_latch_linked_transit_latch = inputs
        .periodic_side_latch_state
        .map(|latch_state| latch_state.linked_transit_latch);
    fields.selected_company_linked_transit_route_anchor_entry_id = inputs
        .market_state
        .and_then(|market_state| market_state.linked_transit_route_anchor_entry_id);
    fields.selected_company_linked_transit_route_anchor_fallback_counts = inputs
        .market_state
        .map(|market_state| {
            market_state
                .linked_transit_route_anchor_fallback_counts
                .clone()
        })
        .unwrap_or_default();
    fields.selected_company_periodic_service_base_route_preference_raw_u8 = inputs
        .periodic_service_state
        .as_ref()
        .and_then(|service_state| service_state.base_route_preference_raw_u8);
    fields.selected_company_periodic_service_effective_route_preference_raw_u8 = inputs
        .periodic_service_state
        .as_ref()
        .and_then(|service_state| service_state.effective_route_preference_raw_u8);
    fields.selected_company_periodic_service_electric_route_preference_override_active = inputs
        .periodic_service_state
        .as_ref()
        .map(|service_state| service_state.electric_route_preference_override_active);
    fields.selected_company_periodic_service_route_quality_multiplier_basis_points = inputs
        .periodic_service_state
        .as_ref()
        .map(|service_state| service_state.effective_route_quality_multiplier_basis_points);
    fields.active_periodic_route_preference_override_company_id = inputs
        .state
        .service_state
        .active_periodic_route_preference_override
        .as_ref()
        .map(|override_state| override_state.company_id);
    fields.active_periodic_route_preference_override_effective_raw_u8 = inputs
        .state
        .service_state
        .active_periodic_route_preference_override
        .as_ref()
        .and_then(|override_state| override_state.effective_route_preference_raw_u8);
    fields.last_periodic_route_preference_override_company_id = inputs
        .state
        .service_state
        .last_periodic_route_preference_override
        .as_ref()
        .map(|override_state| override_state.company_id);
    fields.last_periodic_route_preference_override_effective_raw_u8 = inputs
        .state
        .service_state
        .last_periodic_route_preference_override
        .as_ref()
        .and_then(|override_state| override_state.effective_route_preference_raw_u8);
}
