use serde::{Deserialize, Serialize};

use crate::event::metrics::{
    RuntimeChairmanMetric, RuntimeCompanyMetric, RuntimeTerritoryMetric, RuntimeTrackMetric,
};
use crate::event::targets::{
    RuntimeChairmanTarget, RuntimeCompanyTarget, RuntimePlayerTarget, RuntimeTerritoryTarget,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum RuntimeConditionComparator {
    Ge,
    Le,
    Gt,
    Lt,
    Eq,
    Ne,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "kind", rename_all = "snake_case")]
pub enum RuntimeCondition {
    WorldVariableThreshold {
        index: u32,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    CompanyNumericThreshold {
        target: RuntimeCompanyTarget,
        metric: RuntimeCompanyMetric,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    CompanyVariableThreshold {
        target: RuntimeCompanyTarget,
        index: u32,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    ChairmanNumericThreshold {
        target: RuntimeChairmanTarget,
        metric: RuntimeChairmanMetric,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    PlayerVariableThreshold {
        target: RuntimePlayerTarget,
        index: u32,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    TerritoryNumericThreshold {
        target: RuntimeTerritoryTarget,
        metric: RuntimeTerritoryMetric,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    TerritoryVariableThreshold {
        target: RuntimeTerritoryTarget,
        index: u32,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    CompanyTerritoryNumericThreshold {
        target: RuntimeCompanyTarget,
        territory: RuntimeTerritoryTarget,
        metric: RuntimeTrackMetric,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    SpecialConditionThreshold {
        label: String,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    CandidateAvailabilityThreshold {
        name: String,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    NamedLocomotiveAvailabilityThreshold {
        name: String,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    NamedLocomotiveCostThreshold {
        name: String,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    CargoProductionSlotThreshold {
        slot: u32,
        label: String,
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    CargoProductionTotalThreshold {
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    FactoryProductionTotalThreshold {
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    FarmMineProductionTotalThreshold {
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    OtherCargoProductionTotalThreshold {
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    LimitedTrackBuildingAmountThreshold {
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    TerritoryAccessCostThreshold {
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    EconomicStatusCodeThreshold {
        comparator: RuntimeConditionComparator,
        value: i64,
    },
    WorldFlagEquals {
        key: String,
        value: bool,
    },
}
