// =====================================================================================================================
//  fennec, a free and open source game engine
//  Copyright © 2025 - 2026  Medusa Slockbower
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <https://www.gnu.org/licenses/>.
// =====================================================================================================================

///
/// \file fennec/renderers/vulkan/vkcontext.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 - 2026 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///


#ifndef FENNEC_PLATFORM_VULKAN_VKCONTEXT_H
#define FENNEC_PLATFORM_VULKAN_VKCONTEXT_H

#include <fennec/core/logger.h>
#include <fennec/renderers/interface/gfxcontext.h>
#include <fennec/renderers/vulkan/lib/debug.h>
#include <fennec/renderers/vulkan/lib/instance.h>

namespace fennec
{

///
/// \brief Vulkan Context
class vkcontext : public gfxcontext, public vk::debugger {

// Constructor & Destructor ============================================================================================
public:

	/// \name Constructor & Destructor
	/// @{

	///
	/// \brief Context Constructor
	/// \param display The display server
	/// \param extensions The required extensions for the implementation
	///
	/// \note An override ***should not*** accept \emph{extensions} as an argument and should instead provide it directly
	///       to the constructor for the extensions your implementation needs. For example:
	/// ```cpp
	/// class wayland_vkcontext : public vkcontext {
	///	    wayland_vkcontext(display_server* display)
	///	        : vkcontext(display, { "VK_KHR_wayland_surface" }) {
	///	    }
	/// }
	/// ```
	explicit vkcontext(display_server* display, const dynarray<cstring>& extensions);

	///
	/// \brief Context Destructor
	~vkcontext() override;

	/// @}


// Properties ==========================================================================================================
public:

	/// \name Properties
	/// @{

	///
	/// \brief Context Validity
	/// \returns \emph{true} if the context is initialized and valid, \emph{false} otherwise.
	bool is_valid() override;

	vk::instance* get_instance() {
		return instance.get();
	}

	/// @}


// Debug Callbacks =====================================================================================================
public:

	 void message(uint32_t                 severity,
				  uint32_t                 type,
				  const cstring&           id,
				  const cstring&           message,
				  const dynarray<cstring>& queue,
				  const dynarray<cstring>& commands,
				  const dynarray<string>&  objects) override;

	static uint32_t translate_severity(uint32_t x) {
		switch (x) {
			default:
			case vk::debug_message_severity_info:    return logger::info;
			case vk::debug_message_severity_verbose: return logger::alert;
			case vk::debug_message_severity_warning: return logger::warning;
			case vk::debug_message_severity_error:   return logger::error;
		}
	}

protected:
	unique_ptr<vk::instance> instance;
};

} // fennec

#endif // FENNEC_PLATFORM_VULKAN_VKCONTEXT_H