#pragma once
#include <memory>
#include <Platform/Windows/WindowsWindow.h>

#include "Core.h"
#include "Layer.h"
#include "LayerStack.h"
#include "Log.h"
#include "Hazel/Core/TimeStep.h"
#include "Hazel/ImGui/ImGuiLayer.h"

namespace Hazel {

	struct ApplicationCommandLineArgs
	{
		int count = 0;
		char** args = nullptr;

		const char* operator[](int index)
		{
			if (index >= count)
				HZ_CORE_ERROR("args error");
			return args[count];
		}
	};

	struct ApplicationSpecification
	{
		std::string name = "Application";
		std::string workingDirectory;
		ApplicationCommandLineArgs commandLineArgs;

	};

	class HAZEL_API Application
	{
	public:
		Application(const ApplicationSpecification& specification);
		virtual ~Application();

		void Run();

		void OnEvent(SDL_Event& e);
		void OnWindowResize(SDL_Event& e);
		void PushLayer(Layer* layer);
		void PushOverlay(Layer* layer);

		void Close();

		ImGuiLayer* GetImGuiLayer() const { return m_imguiLayer; }

		inline Window&             GetWindow() const { return *m_Window; }
		inline static Application& Get() { return *s_Instance; }

		const ApplicationSpecification& GetSpecification() const { return m_Specification; }

	private:
		ApplicationSpecification m_Specification;
		Scope<Window> m_Window;
		ImGuiLayer* m_imguiLayer;
		bool m_Running = true;

		LayerStack m_layerStack;

		TimeStep m_TimeStep;
		float m_lastFrameTime = 0.0f;

		bool m_Minimized = false;
	private:
		static Application* s_Instance;
	};

	// to be defined int CLIENT
	Application* CreateApplication(ApplicationCommandLineArgs args);

}
