use std::collections::BTreeSet;

use crate::event::records::RuntimeEventRecordTemplate;

use super::{validate_runtime_condition, validate_runtime_effect};

pub(crate) fn validate_event_record_template(
    record: &RuntimeEventRecordTemplate,
    valid_company_ids: &BTreeSet<u32>,
    valid_player_ids: &BTreeSet<u32>,
    valid_chairman_profile_ids: &BTreeSet<u32>,
    valid_territory_ids: &BTreeSet<u32>,
) -> Result<(), String> {
    for (condition_index, condition) in record.conditions.iter().enumerate() {
        validate_runtime_condition(
            condition,
            valid_company_ids,
            valid_player_ids,
            valid_chairman_profile_ids,
            valid_territory_ids,
        )
        .map_err(|err| {
            format!(
                "template record_id={}.conditions[{condition_index}] {err}",
                record.record_id
            )
        })?;
    }
    for (effect_index, effect) in record.effects.iter().enumerate() {
        validate_runtime_effect(
            effect,
            valid_company_ids,
            valid_player_ids,
            valid_chairman_profile_ids,
            valid_territory_ids,
        )
        .map_err(|err| {
            format!(
                "template record_id={}.effects[{effect_index}] {err}",
                record.record_id
            )
        })?;
    }

    Ok(())
}
