#include "Deer/Enviroment.h"
#include "Deer/Scene.h"
#include "Deer/Memory.h"

#include "DeerStudio/EditorEngine/API/Environment.h"

#include "DeerRender/FrameBuffer.h"
#include "DeerRender/SceneCamera.h"

#include <vector>

namespace Deer {
    namespace EditorEngine {
        // The first element has to allways point to the main scene env
        std::vector <Environment*> environments { &Scene::environment };

        void EnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, SceneCamera& sc) {
            FrameBuffer& frameBuffer = FrameBufferManager::getFrameBuffer(frameBuffer_handle.frameBufferId);
            Environment& env = *environments[environmentId];

            frameBuffer.bind();
            
            // TODO
            env.render(sc);

            frameBuffer.unbind();
        }

        EntityHandleStruct EnvironmentStruct::getRootEntity() {
            return EntityHandleStruct(0, environmentId);
        }

        EntityHandleStruct EnvironmentStruct::getEntity(int id) {
            return EntityHandleStruct(id, environmentId);
        }

        EnvironmentHandleStruct getMainEnvironment() {
            return EnvironmentHandleStruct(0);
        }

        EnvironmentHandleStruct createEnvironment() {
            uint16_t envId = environments.size();
            environments.push_back({});
            
            return EnvironmentHandleStruct(envId);
        }
    }
}