// =====================================================================================================================
//  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/>.
// =====================================================================================================================

#ifndef FENNEC_MATH_DETAIL_VECTOR_TRAITS_H
#define FENNEC_MATH_DETAIL_VECTOR_TRAITS_H

#include <fennec/math/detail/_forward.h>

#include <fennec/lang/type_traits.h>
#include <fennec/math/swizzle.h>

namespace fennec
{

namespace detail
{

// Helpers for vector traits

template<typename>
struct _is_vector_helper
	: false_type {}; // Default false case


template<typename ScalarT, size_t...IndicesV>
struct _is_vector_helper<vector<ScalarT, IndicesV...>>
	: true_type {}; // True for vectors


template<typename VectorT, typename DataT, typename ScalarT, size_t...IndicesV>
struct _is_vector_helper<swizzle<VectorT, DataT, ScalarT, IndicesV...>>
	: true_type {}; // True for swizzles

// get number of components of a type
template<typename>
struct _component_count_helper;

// numeric types reduce to 1
template<typename TypeT> requires(is_arithmetic_v<TypeT>)
struct _component_count_helper<TypeT>
	: integral_constant<size_t, 1> {};

// Vectors reduce to the number of elements
template<typename ScalarT, size_t...IndicesV>
struct _component_count_helper<vector<ScalarT, IndicesV...>>
	: integral_constant<size_t, sizeof...(IndicesV)> {};

// Swizzles reduce to number of elements
template<typename VectorT, typename DataT, typename ScalarT, size_t...IndicesV>
struct _component_count_helper<swizzle<VectorT, DataT, ScalarT, IndicesV...>>
	: integral_constant<size_t, sizeof...(IndicesV)> {};

// Matrices reduce to the number of cells
template<typename ScalarT, size_t RowsV, size_t...ColIndicesV>
struct _component_count_helper<matrix<ScalarT, RowsV, ColIndicesV...>>
	: integral_constant<size_t, RowsV * sizeof...(ColIndicesV)> {};

// default case reduces to 0
template<typename>
struct _component_count_helper
	: integral_constant<size_t, 0> {};

}

}

#endif // FENNEC_MATH_DETAIL_VECTOR_TRAITS_H
