#include "detail/uclass.inl"
#include "detail/view.inl"
#include "detail/field.inl"
#include "std/sarray.h"
namespace refl {
	template<typename T, typename Obj>
	consteval FieldPtr MakeStaticField(T Obj::* ptr, Name name) {
		FieldPtr::Default value;
		Offset offset = 0;
		FieldPtr::Data member = { offset };
		constexpr uint32_t flag = FIELD_MEMBER_FLAG | FIELD_ATTRIBUTE_FLAG;
		return { name, &TypeInfo<T>::StaticClass, member, value, flag };
	}
	template<typename R, typename ...Args>
	consteval FieldPtr MakeStaticField(R(*ptr)(Args...), Name name, const sarray<ArgsValue>& args = {}) {
		uint32_t flag = FIELD_METHOD_FLAG;
		FieldPtr::Default value;
		Offset offset = ArgsValueList::GetArgsSize(args);
		FieldPtr::Data method = { offset };
		return { name, &TypeInfo<real_type_t<R>(*)(real_type_t<Args>...)>::StaticClass, method, value, flag };
	}
	template<typename T, typename R, typename ...Args>
	consteval FieldPtr MakeStaticField(R(T::* ptr)(Args...), Name name, const sarray<ArgsValue>& args = {}) {
		uint32_t flag = FIELD_MEMBER_FLAG | FIELD_METHOD_FLAG;
		FieldPtr::Default value;
		Offset offset = ArgsValueList::GetArgsSize(args);
		FieldPtr::Data method = { offset };
		return { name, &TypeInfo<real_type_t<R>(*)(const void*,real_type_t<Args>...)>::StaticClass, method, value,flag };
	}
	//用处不大---------------begin
	template<typename T>
	consteval int GetStaticFieldID(Name name) {
		auto fields = T::__MakeStaticFields();
		auto first = fields.begin();
		for (auto& field : fields) {
			if (field.name == name) {
				return &field - &*first;
			}
		}
		return 0;
	}
	template<typename T>
	consteval int GetStaticFieldID(bool(* fptr)(FieldPtr)) {
		auto fields = T::__MakeStaticFields();
		auto first = fields.begin();
		for (auto& field : fields) {
			if (fptr(field)) {
				return &field - &*first;
			}
		}
		return 0;
	}
	template<typename T, auto name>
	consteval auto GetStaticField() {
		constexpr auto fields = T::__StaticFields();
		using AutoType = decltype(name);
		if constexpr (std::is_same_v<AutoType, int>) {
			return std::get<name>(fields);
		}
		else {
			constexpr auto id = GetStaticFieldID<T>(Name(name.Data()));
			return std::get<id>(fields);
		}
	}
	//用处不大---------------end
}