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

pub(in crate::inspect::smp) fn runtime_effect_supported_for_save_import(
    effect: &RuntimeEffect,
) -> bool {
    match effect {
        RuntimeEffect::SetChairmanCash { target, .. }
        | RuntimeEffect::DeactivateChairman { target } => matches!(
            target,
            RuntimeChairmanTarget::AllActive
                | RuntimeChairmanTarget::HumanChairmen
                | RuntimeChairmanTarget::AiChairmen
                | RuntimeChairmanTarget::SelectedChairman
                | RuntimeChairmanTarget::ConditionTrueChairman
                | RuntimeChairmanTarget::Ids { .. }
        ),
        RuntimeEffect::SetWorldFlag { .. }
        | RuntimeEffect::SetWorldVariable { .. }
        | RuntimeEffect::SetLimitedTrackBuildingAmount { .. }
        | RuntimeEffect::SetEconomicStatusCode { .. }
        | RuntimeEffect::SetCompanyGovernanceScalar { .. }
        | RuntimeEffect::SetCandidateAvailability { .. }
        | RuntimeEffect::SetNamedLocomotiveAvailability { .. }
        | RuntimeEffect::SetNamedLocomotiveAvailabilityValue { .. }
        | RuntimeEffect::SetNamedLocomotiveCost { .. }
        | RuntimeEffect::SetCargoPriceOverride { .. }
        | RuntimeEffect::SetCargoProductionOverride { .. }
        | RuntimeEffect::SetCargoProductionSlot { .. }
        | RuntimeEffect::SetWorldScalarOverride { .. }
        | RuntimeEffect::SetTerritoryAccessCost { .. }
        | RuntimeEffect::SetSpecialCondition { .. }
        | RuntimeEffect::ConfiscateCompanyAssets { .. }
        | RuntimeEffect::DeactivateCompany { .. }
        | RuntimeEffect::DeactivatePlayer { .. }
        | RuntimeEffect::SetCompanyTrackLayingCapacity { .. }
        | RuntimeEffect::RetireTrains { .. }
        | RuntimeEffect::ActivateEventRecord { .. }
        | RuntimeEffect::DeactivateEventRecord { .. }
        | RuntimeEffect::RemoveEventRecord { .. } => true,
        RuntimeEffect::SetPlayerCash { target, .. }
        | RuntimeEffect::SetPlayerVariable { target, .. } => matches!(
            target,
            RuntimePlayerTarget::AllActive
                | RuntimePlayerTarget::Ids { .. }
                | RuntimePlayerTarget::HumanPlayers
                | RuntimePlayerTarget::AiPlayers
                | RuntimePlayerTarget::SelectedPlayer
                | RuntimePlayerTarget::ConditionTruePlayer
        ),
        RuntimeEffect::SetCompanyTerritoryAccess {
            target, territory, ..
        } => {
            matches!(
                target,
                RuntimeCompanyTarget::AllActive
                    | RuntimeCompanyTarget::Ids { .. }
                    | RuntimeCompanyTarget::HumanCompanies
                    | RuntimeCompanyTarget::AiCompanies
                    | RuntimeCompanyTarget::SelectedCompany
                    | RuntimeCompanyTarget::ConditionTrueCompany
            ) && matches!(
                territory,
                RuntimeTerritoryTarget::AllTerritories | RuntimeTerritoryTarget::Ids { .. }
            )
        }
        RuntimeEffect::SetCompanyCash { target, .. }
        | RuntimeEffect::SetCompanyVariable { target, .. }
        | RuntimeEffect::AdjustCompanyCash { target, .. }
        | RuntimeEffect::AdjustCompanyDebt { target, .. } => matches!(
            target,
            RuntimeCompanyTarget::AllActive
                | RuntimeCompanyTarget::Ids { .. }
                | RuntimeCompanyTarget::HumanCompanies
                | RuntimeCompanyTarget::AiCompanies
                | RuntimeCompanyTarget::SelectedCompany
                | RuntimeCompanyTarget::ConditionTrueCompany
        ),
        RuntimeEffect::SetTerritoryVariable { target, .. } => matches!(
            target,
            RuntimeTerritoryTarget::AllTerritories | RuntimeTerritoryTarget::Ids { .. }
        ),
        RuntimeEffect::AppendEventRecord { record } => record
            .effects
            .iter()
            .all(runtime_effect_supported_for_save_import),
    }
}

pub(in crate::inspect::smp) fn runtime_condition_supported_for_save_import(
    condition: &RuntimeCondition,
) -> bool {
    match condition {
        RuntimeCondition::WorldVariableThreshold { .. }
        | RuntimeCondition::CompanyNumericThreshold { .. }
        | RuntimeCondition::CompanyVariableThreshold { .. }
        | RuntimeCondition::PlayerVariableThreshold { .. }
        | RuntimeCondition::ChairmanNumericThreshold { .. }
        | RuntimeCondition::TerritoryNumericThreshold { .. }
        | RuntimeCondition::TerritoryVariableThreshold { .. }
        | RuntimeCondition::CompanyTerritoryNumericThreshold { .. }
        | RuntimeCondition::SpecialConditionThreshold { .. }
        | RuntimeCondition::CandidateAvailabilityThreshold { .. }
        | RuntimeCondition::NamedLocomotiveAvailabilityThreshold { .. }
        | RuntimeCondition::NamedLocomotiveCostThreshold { .. }
        | RuntimeCondition::CargoProductionSlotThreshold { .. }
        | RuntimeCondition::CargoProductionTotalThreshold { .. }
        | RuntimeCondition::FactoryProductionTotalThreshold { .. }
        | RuntimeCondition::FarmMineProductionTotalThreshold { .. }
        | RuntimeCondition::OtherCargoProductionTotalThreshold { .. }
        | RuntimeCondition::LimitedTrackBuildingAmountThreshold { .. }
        | RuntimeCondition::TerritoryAccessCostThreshold { .. }
        | RuntimeCondition::EconomicStatusCodeThreshold { .. }
        | RuntimeCondition::WorldFlagEquals { .. } => true,
    }
}
