use std::collections::HashSet;

use crate::{DbIndex, LuaMemberKey};

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TypeCheckCheckLevel {
    Normal,
    GenericConditional,
}

#[derive(Debug, Clone)]
pub struct TypeCheckContext<'db> {
    pub detail: bool,
    pub db: &'db DbIndex,
    pub level: TypeCheckCheckLevel,
    pub table_member_checked: Option<HashSet<LuaMemberKey>>,
}

impl<'db> TypeCheckContext<'db> {
    pub fn new(db: &'db DbIndex, detail: bool, level: TypeCheckCheckLevel) -> Self {
        Self {
            detail,
            db,
            level,
            table_member_checked: None,
        }
    }

    pub fn is_key_checked(&self, key: &LuaMemberKey) -> bool {
        if let Some(checked) = &self.table_member_checked {
            checked.contains(key)
        } else {
            false
        }
    }

    pub fn mark_key_checked(&mut self, key: LuaMemberKey) {
        if self.table_member_checked.is_none() {
            self.table_member_checked = Some(HashSet::new());
        }
        if let Some(checked) = &mut self.table_member_checked {
            checked.insert(key);
        }
    }
}
