#include <ehs/Log.h>
#include <ehs/GC.h>
#include <lwe/GameLoop.h>
#include <lwe/RenderWindow.h>

#include <ehs/io/Console.h>

#include "Levels/Game.h"

ehs::SInt_32 Main(ehs::Str_8* appName, ehs::Str_8* appVerId, ehs::Version* appVer)
{
	*appName = "Pong";
	*appVerId = "Release";
	*appVer = {1, 0, 0};

	ehs::Log::EnableImmediateMode(true);

	ehs::Console::Attach();

	#if defined(EHS_OS_WINDOWS)
		lwe::GpuInstance::AddExtension(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
	#elif defined(EHS_OS_LINUX)
		lwe::GpuInstance::AddExtension(VK_KHR_XCB_SURFACE_EXTENSION_NAME);
	#endif

	lwe::GpuInstance::AddExtension(VK_KHR_SURFACE_EXTENSION_NAME);

	lwe::GpuInstance::Initialize(false);

	lwe::GpuDevice primary = lwe::GpuDevice::GetBest();

	lwe::GpuQueueFamily* family = primary.GetQueueFamily(lwe::QueueType::GRAPHICS);

	lwe::GpuInterface inf(&primary);
	inf.AddExtensions(VK_KHR_SWAPCHAIN_EXTENSION_NAME);

	lwe::GpuQueue queue(family, &inf, 1.0f);

	inf.Initialize();

	lwe::RenderWindow win(&inf, &queue);
	win.Create_8(*appName, {0, 0}, {1024, 768});
	win.Show();

	lwe::GameLoop gl(&win, 6, 0);
	gl.AddLevel(new Game());

	gl.Initialize();
	gl.Start();
	gl.UnInitialize();

	win.Close();

	inf.Release();

	lwe::GpuInstance::Release();

	return 0;
}