use super::super::super::*;
use super::cargo::{
    recovered_cargo_economics_descriptor_metadata, recovered_cargo_price_descriptor_metadata,
    recovered_cargo_production_descriptor_metadata,
};
use super::locomotives::{
    recovered_locomotive_availability_descriptor_metadata,
    recovered_locomotive_cost_descriptor_metadata, recovered_locomotive_policy_descriptor_metadata,
};
use super::special_conditions::{
    special_condition_world_scalar_descriptor_metadata,
    special_condition_world_toggle_descriptor_metadata,
};

pub(in crate::inspect::smp) fn real_grouped_effect_descriptor_metadata(
    descriptor_id: u32,
) -> Option<RealGroupedEffectDescriptorMetadata> {
    recovered_cargo_price_descriptor_metadata(descriptor_id)
        .or_else(|| recovered_cargo_economics_descriptor_metadata(descriptor_id))
        .or_else(|| recovered_cargo_production_descriptor_metadata(descriptor_id))
        .or_else(|| recovered_locomotive_availability_descriptor_metadata(descriptor_id))
        .or_else(|| recovered_locomotive_cost_descriptor_metadata(descriptor_id))
        .or_else(|| recovered_territory_access_cost_descriptor_metadata(descriptor_id))
        .or_else(|| recovered_locomotive_policy_descriptor_metadata(descriptor_id))
        .or_else(|| special_condition_world_scalar_descriptor_metadata(descriptor_id))
        .or_else(|| special_condition_world_toggle_descriptor_metadata(descriptor_id))
        .or_else(|| {
            REAL_GROUPED_EFFECT_DESCRIPTOR_METADATA
                .iter()
                .copied()
                .find(|metadata| metadata.descriptor_id == descriptor_id)
        })
        .or_else(|| {
            checked_in_event_effect_descriptor_rows()
                .get(&descriptor_id)
                .copied()
        })
}

fn recovered_territory_access_cost_descriptor_metadata(
    descriptor_id: u32,
) -> Option<RealGroupedEffectDescriptorMetadata> {
    (descriptor_id == 453).then_some(RealGroupedEffectDescriptorMetadata {
        descriptor_id,
        label: "Territory Access Cost",
        target_mask_bits: 0x08,
        parameter_family: "territory_access_cost_scalar",
        runtime_key: None,
        runtime_status: RealGroupedEffectRuntimeStatus::Executable,
        executable_in_runtime: true,
    })
}
