use super::super::super::blockers::{
    runtime_effect_uses_condition_true_company, runtime_effect_uses_condition_true_player,
};
use crate::event::conditions::RuntimeCondition;
use crate::event::targets::{RuntimeCompanyTarget, RuntimePlayerTarget};
use crate::inspect::smp::events::SmpLoadedPackedEventRecordSummary;

pub(crate) fn record_uses_condition_true_company(
    record: &SmpLoadedPackedEventRecordSummary,
) -> bool {
    record
        .decoded_conditions
        .iter()
        .any(condition_uses_condition_true_company)
        || record
            .decoded_actions
            .iter()
            .any(runtime_effect_uses_condition_true_company)
}

pub(crate) fn record_uses_condition_true_player(
    record: &SmpLoadedPackedEventRecordSummary,
) -> bool {
    record
        .decoded_actions
        .iter()
        .any(runtime_effect_uses_condition_true_player)
}

pub(crate) fn condition_uses_condition_true_company(condition: &RuntimeCondition) -> bool {
    match condition {
        RuntimeCondition::CompanyNumericThreshold { target, .. }
        | RuntimeCondition::CompanyVariableThreshold { target, .. }
        | RuntimeCondition::CompanyTerritoryNumericThreshold { target, .. } => {
            matches!(target, RuntimeCompanyTarget::ConditionTrueCompany)
        }
        RuntimeCondition::PlayerVariableThreshold { target, .. } => {
            matches!(target, RuntimePlayerTarget::ConditionTruePlayer)
        }
        RuntimeCondition::ChairmanNumericThreshold { .. } => false,
        RuntimeCondition::TerritoryNumericThreshold { .. }
        | RuntimeCondition::TerritoryVariableThreshold { .. }
        | RuntimeCondition::WorldVariableThreshold { .. }
        | 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 { .. } => false,
    }
}
