#pragma once
#include "field.h"
namespace refl {
	template<typename T, typename R, typename ...Args>
	consteval auto fetch_method_t(R(T::*)(Args...)) {
		using MethodType = R(*)(const void*, Args...);
		return MethodType{ nullptr };
	}
	template<typename R, typename ...Args>
	consteval auto fetch_method_t(R(*)(Args...)) {
		using MethodType = R(*)(Args...);
		return MethodType{ nullptr };
	}
	template<typename Tuple, int Index>
	consteval int fetch_tuple_elm_size(int first = 0) {
		using T = std::tuple_element<Index, Tuple>::type;
		if constexpr (std::is_same_v<T, void>) {
			return 0;
		}
		else {
			return Index >= first ? sizeof(T) : 0;
		}
	}
	template<typename Tuple, std::size_t... Is>
	consteval int fetch_tuple_size(std::index_sequence<Is...>, int first = 0) {
		int size = 0;
		(..., (size += fetch_tuple_elm_size<Tuple, Is>(first)));
		return size;
	}
	template<typename T>
	consteval int fetch_meta_size() {
		auto fields = T::__MakeStaticFields();
		int size = 0;
		for (auto& field : fields) {
			size += field.data.member.offset;
		}
		if (size == 0) {
			size = 1;
		}
		return size;
	}
	enum MetaFlag :uint32_t {
		META_NONE_FLAG = 0,
		META_SERIZLE_FLAG = 1 << 0,
		META_UI_FLAG = 1 << 0,
	};
	class UClass;
	class MetaHelp {
	public:
		template<typename T, typename... Args>
		static FieldPtr CtorField(T(*ptr)(Args...), char*& memory, const MethodData& data = {});

		template<typename T, typename Obj>
		static FieldPtr MemberField(T Obj::* ptr, const Name& name, char*& memory, const MemberData& data = {});

		template<typename R, typename ...Args>
		static FieldPtr MethodField(R(*ptr)(Args...), const Name& name,char*& memory, const MethodData& data = {});

		template<typename T,typename R, typename ...Args>
		static FieldPtr MethodField(R(T::*ptr)(Args...), const Name& name,char*& memory, const MethodData& data = {});

		template<typename T, typename R, typename ...Args>
		static FieldPtr MethodField(R(T::* ptr)(Args...)const, const Name& name, char*& memory, const MethodData& data = {});
	};
}