//! @interface-stub
use crate::records::generic_type_visitor::GenericTypeVisitorTrait;
use crate::records::index_collector::IndexCollector;
use crate::records::indexer_index_collector::IndexerIndexCollector;
use crate::records::singleton_type::SingletonType;
use crate::records::string_singleton::StringSingleton;
use crate::records::table_type::TableType;
use crate::type_aliases::singleton_variant::SingletonVariant;
use crate::type_aliases::type_id::TypeId;

impl IndexCollector {
    pub fn visit_type_id_table_type(&mut self, _ty: TypeId, ttv: &TableType) -> bool {
        unsafe {
            for (name, _) in ttv.props.iter() {
                let singleton = (*self.arena).add_type(SingletonType::singleton_type(
                    SingletonVariant::V1(StringSingleton::new(name.clone())),
                ));
                self.indexes.insert_type_id(singleton);
            }

            if let Some(indexer) = &ttv.indexer {
                let mut iic = IndexerIndexCollector::new(&mut self.indexes as *mut _);
                iic.traverse_type_id(indexer.index_type);
            }
        }

        false
    }
}
