#include "addons/addons.h"
#include "datastructure/vec.h"
#include "siecs.h"
#ifndef SIREFLECT_H
#include "sireflect.h"
#endif
#include "storage/table_index.h"
#include "world_internal.h"

ECS_RELATION_DEFINE(ChildOf, EcsRelationCascadeDelete);
ECS_COMPONENT_DEFINE(Name);
ECS_COMPONENT_DEFINE(Disabled);
ECS_COMPONENT_DEFINE(Abstract);

void ecs_bootstrap(ecs_world_t *world) {
    // Reserve identifiers used to represent false return values.
    ecs_table_index_get_or_create(world, (ecs_type_t){ 0 });
    ecs_vec_push_u64(&world->entity_index.entities, 0);
    ecs_component(world, { .name = "Invalid" });

    // Register the ecs_entity_t struct reflection.
    sireflect_register_struct(
        world->sireflect_registry,
        &(sireflect_struct_desc_t){
            .name = "ecs_entity_t",
            .fields = "{ uint32_t id; uint32_t generation; }",
            .size = sizeof(ecs_entity_t),
            .align = _Alignof(ecs_entity_t),
        }
    );

    ECS_COMPONENT_REGISTER(world, ChildOf);
    ECS_COMPONENT_REGISTER(world, Name);
    ECS_COMPONENT_REGISTER(world, Disabled);
    ECS_COMPONENT_REGISTER(world, Abstract);

    init_rest(world);
}
