use std::collections::BTreeSet;

#[derive(Debug, Default)]
pub(in crate::engine) struct ResolvedConditionContext {
    pub(in crate::engine) matching_company_ids: BTreeSet<u32>,
    pub(in crate::engine) matching_player_ids: BTreeSet<u32>,
    pub(in crate::engine) matching_chairman_profile_ids: BTreeSet<u32>,
}

pub(super) fn intersect_company_matches(
    company_matches: &mut Option<BTreeSet<u32>>,
    next: BTreeSet<u32>,
) {
    match company_matches {
        Some(existing) => {
            existing.retain(|company_id| next.contains(company_id));
        }
        None => {
            *company_matches = Some(next);
        }
    }
}

pub(super) fn intersect_player_matches(
    player_matches: &mut Option<BTreeSet<u32>>,
    next: BTreeSet<u32>,
) {
    match player_matches {
        Some(existing) => {
            existing.retain(|player_id| next.contains(player_id));
        }
        None => {
            *player_matches = Some(next);
        }
    }
}

pub(super) fn intersect_chairman_matches(
    chairman_matches: &mut Option<BTreeSet<u32>>,
    next: BTreeSet<u32>,
) {
    match chairman_matches {
        Some(existing) => {
            existing.retain(|profile_id| next.contains(profile_id));
        }
        None => {
            *chairman_matches = Some(next);
        }
    }
}
