#pragma once
#include <vector>
#include "sre/SDLRenderer.hpp"
#include <stdlib.h>
#include "GameObject.hpp"
#include "SpriteRenderer.hpp"
#include "CameraComponent.hpp"
#include "Transform.hpp"
#include "PhysicsBody.hpp"
#include "CharacterController.h"
#include "rapidjson/rapidjson.h"
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "Box2D/Dynamics/b2World.h"
#include "sre/SpriteAtlas.hpp"
#include "sre/Texture.hpp"
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include "Logger.hpp"


struct Level
{
	std::shared_ptr<GameObject> levelObj;
	std::shared_ptr<GameObject> cameraObject;
	std::vector<std::shared_ptr<GameObject>> levelObjects;
	float deathLevelInY;
	sre::Camera* camera;
	std::shared_ptr<GameObject> playerObject;
};

class LevelBuilder
{
public:
	LevelBuilder(
		Event<void(float)>*,
		Event<void(sre::SpriteBatch::SpriteBatchBuilder&)>*,
		Event<void()>*,
		Event<void(SDL_Event&)>*,
		std::shared_ptr<b2World>);
	~LevelBuilder();

	Level BuildFromFile(std::string);
	std::vector<std::shared_ptr<GameObject>> GameObjects;
	
private:
	
	Level LoadLevel(std::string);
	std::shared_ptr<GameObject> MakeGameObject(int, Level*);

	Event<void(float)>* updateEvent;
	Event<void(sre::SpriteBatch::SpriteBatchBuilder&)>* drawEvent;
	Event<void()>* physicsEvent;
	Event<void(SDL_Event&)>* keyEvent;
	std::shared_ptr<b2World> physicsWorld;
};