// =====================================================================================================================
//  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_METAPROGRAMMING_TYPE_NAME_H
#define FENNEC_METAPROGRAMMING_TYPE_NAME_H

#include <fstream>

namespace fennec::detail
{

template<typename T>
inline static const char* f() {
	return __PRETTY_FUNCTION__;
}

}

inline void type_name_h()
{

	std::ofstream out("fennec/rtti/detail/_constants.h");

	out << "// =====================================================================================================================" << std::endl;
	out << "//  fennec, a free and open source game engine" << std::endl;
	out << "//  Copyright © 2025 - 2026  Medusa Slockbower" << std::endl;
	out << "//" << std::endl;
	out << "//  This program is free software: you can redistribute it and/or modify" << std::endl;
	out << "//  it under the terms of the GNU General Public License as published by" << std::endl;
	out << "//  the Free Software Foundation, either version 3 of the License, or" << std::endl;
	out << "//  (at your option) any later version." << std::endl;
	out << "//" << std::endl;
	out << "//  This program is distributed in the hope that it will be useful," << std::endl;
	out << "//  but WITHOUT ANY WARRANTY; without even the implied warranty of" << std::endl;
	out << "//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the" << std::endl;
	out << "//  GNU General Public License for more details." << std::endl;
	out << "//" << std::endl;
	out << "//  You should have received a copy of the GNU General Public License" << std::endl;
	out << "//  along with this program.  If not, see <https://www.gnu.org/licenses/>." << std::endl;
	out << "// =====================================================================================================================" << std::endl;

	out << "" << std::endl;

	out << "#ifndef FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl;
	out << "#define FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl;

	out << "" << std::endl;

	out << "#include <fennec/lang/types.h>" << std::endl;

	out << "" << std::endl;

	out << "namespace fennec::detail" << std::endl;
	out << "{" << std::endl;
	out << "" << std::endl;


	std::string str = fennec::detail::f<void>();
	const size_t heading = str.find("void");
	const size_t footing = str.size() - (heading + 4);

	out << "// " << str << std::endl;
	out << "inline static constexpr size_t type_name_f_heading = " << heading << ";" << std::endl;
	out << "inline static constexpr size_t type_name_f_footing = " << footing << ";" << std::endl;


	out << "" << std::endl;
	out << "}" << std::endl;

	out << "" << std::endl;

	out << "#endif // FENNEC_RTTI_DETAIL_CONSTANTS_H" << std::endl;

	out.close();

	return;
}


#endif // FENNEC_METAPROGRAMMING_TYPE_NAME_H