use crate::engine::targets::resolve_territory_target_ids;
use crate::event::targets::RuntimeTerritoryTarget;
use crate::state::RuntimeState;

pub(super) fn apply_set_territory_variable(
    state: &mut RuntimeState,
    target: &RuntimeTerritoryTarget,
    index: u32,
    value: i64,
) -> Result<(), String> {
    let territory_ids = resolve_territory_target_ids(state, target)?;
    for territory_id in territory_ids {
        state
            .territory_runtime_variables
            .entry(territory_id)
            .or_default()
            .insert(index, value);
    }
    Ok(())
}

pub(super) fn apply_set_territory_access_cost(state: &mut RuntimeState, value: u32) {
    state.world_restore.territory_access_cost = Some(value);
}
