/*
 * 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 "BaseInputAction.hpp"
#include "InputKey.hpp"

namespace OpenVulkano::Input
{
	struct KeyBinding
	{
		const InputKey key;
		float scale;

		KeyBinding(InputKey keyBinding, float scaleFactor)
				: key(keyBinding), scale(scaleFactor)
		{}
	};

	struct AxisButtonBinding
	{
		const InputKey positive;
		const InputKey negative;
		float scale;

		AxisButtonBinding(InputKey pos, InputKey neg, float scaleFactor)
				: positive(pos), negative(neg), scale(scaleFactor)
		{}
	};

	class InputAction final : public BaseInputAction
	{
		std::vector<KeyBinding> keys;
		std::vector<AxisButtonBinding> axisButtons;

	public:
		InputAction(const std::string& name) : BaseInputAction(name)
		{}

		[[nodiscard]] const std::vector<KeyBinding>& GetKeys() const
		{
			return keys;
		}

		[[nodiscard]] const std::vector<AxisButtonBinding>& GetAxisButtons() const
		{
			return axisButtons;
		}

		void BindKey(InputKey key, float scale = 1)
		{
			for (auto& binding : keys)
			{
				if (binding.key == key)
				{
					binding.scale = scale;
					return;
				}
			}
			keys.emplace_back(key, scale);
		}

		void BindAxisButtons(InputKey keyPositive, InputKey keyNegative, float scale = 1)
		{
			for (auto& binding : axisButtons)
			{
				if (binding.positive == keyPositive && binding.negative == keyNegative)
				{
					binding.scale = scale;
					return;
				}
			}
			axisButtons.emplace_back(keyPositive, keyNegative, scale);
		}
	};
}