// =====================================================================================================================
//  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/math/swizzle.h
/// \brief \ref fennec_math_swizzle
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 - 2026 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///

#ifndef FENNEC_MATH_SWIZZLE_H
#define FENNEC_MATH_SWIZZLE_H

///
///
/// \page fennec_math_swizzle Swizzling
///
/// \brief A submodule of the fennec Vector Math Module, used for "swizzling" vectors.
///
/// \code #include <fennec/math/swizzle.h> \endcode
///
///

#include <fennec/lang/metasequences.h>

#include <fennec/math/swizzle_storage.h>

namespace fennec
{

///
/// \brief Structure for Handling Vector Swizzling
///
/// \details
/// \tparam VectorT Vector Type
/// \tparam DataT Base Data Type
/// \tparam ScalarT Scalar Base Type
/// \tparam IndicesV Swizzle Indices
template<typename VectorT, typename DataT, typename ScalarT, size_t...IndicesV>
struct swizzle : public detail::swizzle_storage<DataT, ScalarT, IndicesV...>
{
public:

	///
	/// \brief alias for the scalar type
	using scalar_t = ScalarT;

	///
	/// \name aliases for the size
	/// @{
	inline static constexpr size_t dimension      = sizeof...(IndicesV); //!< \brief dimension of the swizzle
	inline static constexpr size_t num_components = sizeof...(IndicesV); //!< \brief number of components
	inline static constexpr size_t size           = sizeof...(IndicesV); //!< \brief size of the swizzle
	inline static constexpr size_t N              = sizeof...(IndicesV); //!< \brief size of the swizzle
	/// @}

	///
	/// \brief  Decay the Swizzle into a Vector
	/// \return The Value of the Swizzle as a Vector
	constexpr VectorT decay() const {
		VectorT res;
		return decay_impl(res, make_index_metasequence<size>{});
	}

	///
	/// \brief Vector Cast Operator
    /// \returns The Value of the Swizzle as a Vector
	constexpr explicit operator VectorT() const {
		return decay();
	}

	swizzle() = default;

private:
	template<size_t...VecIndicesV>
	constexpr VectorT& decay_impl(VectorT& vec, index_metasequence<VecIndicesV...>) {
		return ((vec[VecIndicesV] = this->data[IndicesV]), ..., vec);
	}
};

}

#endif // FENNEC_MATH_SWIZZLE_H
