#include "raylib.h"
#include "test_object.h"
#include "core/camera_node.h"
#include "core/engine_global.h"
#include "core/engine_loop.h"
#include "core/scene.h"
#include "core/transform_node.h"
#include "core/mesh_render_entity.h"
#include "utils/debug.h"

Scene *CreateInitialScene() {
    Transformable transformable;
    Transform transform;
    SceneNode *root = CreateTransformNode();
    // create a model with a camera attached as a child of the root of the scene
    SceneNode *model_parent = CreateTransformNode();
    SceneNodeAddChild(root, model_parent);
    // create the rest of the scene with a mesh and a functionality node
    SceneNodeAddChild(model_parent, CreateMeshRenderEntity("spacefighter"));
    SceneNodeAddChild(model_parent, CreateTestObject());
    transformable = TC_CAST(model_parent->entity, Transformable);
    transform = transformable.tc->get_global_transform(transformable.data);
    transform.translation.y += 10;
    transformable.tc->set_global_transform(transformable.data, transform);
    // create a camera attached to it's own transform node
    SceneNode *camera_parent = CreateTransformNode(); // the parent
    SceneNodeAddChild(model_parent, camera_parent); // attached to the model parent
    // set camera parent offset
    transformable = TC_CAST(camera_parent->entity, Transformable);
    transform = transformable.tc->get_transform(transformable.data);
    transform.translation = (Vector3){-3.f, 3.f, -10.f};
    transform.rotation = QuaternionFromEuler(7.5f * DEG2RAD, 0.f, 0.f);
    transformable.tc->set_transform(transformable.data, transform);
    // create the camera and attach it to the dedicated transform node
    SceneNodeAddChild(camera_parent, CreateCameraNode());
    return CreateScene(root);
}

int main() {
    InitializeEngine();
    RunGame(CreateInitialScene());
    UNREACHABLE("main: End of main function reached. This is an error, call ShutDown() when exiting instead.");
}
