use crate::state::RuntimeState;

pub(super) fn apply_set_world_flag(state: &mut RuntimeState, key: &str, value: bool) {
    state.world_flags.insert(key.to_string(), value);
    let raw = u8::from(value);
    match key {
        "world.all_steam_locos_available" => {
            state.world_restore.all_steam_locomotives_available_raw_u8 = Some(raw);
            state.world_restore.all_steam_locomotives_available_enabled = Some(value);
        }
        "world.all_diesel_locos_available" => {
            state.world_restore.all_diesel_locomotives_available_raw_u8 = Some(raw);
            state.world_restore.all_diesel_locomotives_available_enabled = Some(value);
        }
        "world.all_electric_locos_available" => {
            state
                .world_restore
                .all_electric_locomotives_available_raw_u8 = Some(raw);
            state
                .world_restore
                .all_electric_locomotives_available_enabled = Some(value);
        }
        _ => {}
    }
}

pub(super) fn apply_set_world_scalar_override(state: &mut RuntimeState, key: &str, value: i64) {
    state.world_scalar_overrides.insert(key.to_string(), value);
}

pub(super) fn apply_set_limited_track_building_amount(state: &mut RuntimeState, value: i32) {
    state.world_restore.limited_track_building_amount = Some(value);
}

pub(super) fn apply_set_economic_status_code(state: &mut RuntimeState, value: i32) {
    state.world_restore.economic_status_code = Some(value);
}

pub(super) fn apply_set_world_variable(state: &mut RuntimeState, index: u32, value: i64) {
    state.world_runtime_variables.insert(index, value);
}

pub(super) fn apply_set_special_condition(state: &mut RuntimeState, label: &str, value: u32) {
    state.special_conditions.insert(label.to_string(), value);
}
