use crate::event::targets::{RuntimeCargoPriceTarget, RuntimeCargoProductionTarget};
use crate::state::RuntimeState;

pub(super) fn apply_set_candidate_availability(state: &mut RuntimeState, name: &str, value: u32) {
    state.candidate_availability.insert(name.to_string(), value);
}

pub(super) fn apply_set_named_locomotive_availability(
    state: &mut RuntimeState,
    name: &str,
    value: bool,
) {
    state
        .named_locomotive_availability
        .insert(name.to_string(), u32::from(value));
}

pub(super) fn apply_set_named_locomotive_availability_value(
    state: &mut RuntimeState,
    name: &str,
    value: u32,
) {
    state
        .named_locomotive_availability
        .insert(name.to_string(), value);
}

pub(super) fn apply_set_named_locomotive_cost(state: &mut RuntimeState, name: &str, value: u32) {
    state.named_locomotive_cost.insert(name.to_string(), value);
}

pub(super) fn apply_set_cargo_price_override(
    state: &mut RuntimeState,
    target: &RuntimeCargoPriceTarget,
    value: u32,
) {
    match target {
        RuntimeCargoPriceTarget::All => {
            state.all_cargo_price_override = Some(value);
        }
        RuntimeCargoPriceTarget::Named { name } => {
            state
                .named_cargo_price_overrides
                .insert(name.clone(), value);
        }
    }
}

pub(super) fn apply_set_cargo_production_override(
    state: &mut RuntimeState,
    target: &RuntimeCargoProductionTarget,
    value: u32,
) {
    match target {
        RuntimeCargoProductionTarget::All => {
            state.all_cargo_production_override = Some(value);
        }
        RuntimeCargoProductionTarget::Factory => {
            state.factory_cargo_production_override = Some(value);
        }
        RuntimeCargoProductionTarget::FarmMine => {
            state.farm_mine_cargo_production_override = Some(value);
        }
        RuntimeCargoProductionTarget::Named { name } => {
            state
                .named_cargo_production_overrides
                .insert(name.clone(), value);
        }
    }
}

pub(super) fn apply_set_cargo_production_slot(state: &mut RuntimeState, slot: u32, value: u32) {
    state.cargo_production_overrides.insert(slot, value);
}
