/*
PolyGun

Copyright (c) 2023 mrkubax10 <mrkubax10@onet.pl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#ifndef POLYGUN_SERVER_MOD_API_HPP
#define POLYGUN_SERVER_MOD_API_HPP

#include <angelscript.h>
#include <string>

namespace polygun::server::mod_api {
	// Logging
	void log_info(asIScriptGeneric* args);
	void log_warning(asIScriptGeneric* args);
	void log_error(asIScriptGeneric* args);
	void log_fatal(asIScriptGeneric* args);
	void log_verbose(asIScriptGeneric* args);
	// Util classes
	class RefCounted {
	public:
		RefCounted(asIScriptObject* script_obj);
		virtual ~RefCounted();

		void reference();
		void release();

	private:
		size_t m_ref_count;

	protected:
		asIScriptObject* m_script_obj;
		asILockableSharedBool* m_active;
	};
	// Registering nodes
	class Node : public RefCounted {
	public:
		Node(asIScriptObject* script_obj);
		~Node() = default;
		// Weird C++ stuff
		// NOTE: Every class member has to be added there otherwise during assignment
		// it won't be copied
		Node& operator=(const Node& other) { return *this; }

		// Overridable in scripts
		// if set then this texture will be used for all faces
		std::string get_texture_filename();
		// if not set then texture_filename will be used
		std::string get_display_icon();
		// used to set different textures for each face, if not set then `get_texture_filename` will be used
		std::string get_top_texture_filename();
		std::string get_bottom_texture_filename();
		std::string get_left_texture_filename();
		std::string get_right_texture_filename();
		std::string get_front_texture_filename();
		std::string get_back_texture_filename();

		static Node* create();
	};
	void register_node(asIScriptGeneric* args);
}

#endif // POLYGUN_SERVER_MOD_API_HPP
