/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <magic_enum.hpp>

namespace OpenVulkano::AR
{
	class ArType final
	{
		static inline constexpr std::string_view HUMAN_READABLE_NAMES[] = { "Unknown", "ARKit", "ARCore" };

	public:
		enum Type : uint8_t { UNKNOWN = 0, AR_KIT, AR_CORE };

		ArType() : ArType(UNKNOWN) {}

		ArType(Type type) : m_type(type) {}

		[[nodiscard]] std::string_view GetName() const
		{
			return magic_enum::enum_name(m_type);
		}

		static ArType GetFromName(std::string_view name)
		{
			auto result = magic_enum::enum_cast<Type>(name);
			if (result.has_value()) return { result.value() };
			return GetFromHumanReadableName(name);
		}

		[[nodiscard]] const std::string_view& GetHumanReadableName() const
		{
			return HUMAN_READABLE_NAMES[m_type];
		}

		static ArType GetFromHumanReadableName(const std::string_view& name)
		{
			uint8_t i = 0;
			for (const std::string_view& n : HUMAN_READABLE_NAMES)
			{
				if (n == name) return {static_cast<Type>(i)};
				i++;
			}
			return UNKNOWN;
		}

	private:
		Type m_type;
	};
}