#pragma once

#include "ehs/EHS.h"
#include "ehs/Serializer.h"
#include "ehs/Str.h"

namespace ehs
{
	class DbVar;

	class EHS_LIB_IO DbVarTmpl
	{
	private:
		friend class DbTable;

		UInt_64 hashId;
		Str_8 id;
		Byte* def;
		UInt_64 size;

	public:
		~DbVarTmpl();

		DbVarTmpl();

		template<typename T>
		DbVarTmpl(Str_8 id, const T* const def, UInt_64 size)
			: hashId(id.Hash_64()), id((Str_8&&)id), def(new Byte[sizeof(T) * size]), size(sizeof(T) * size)
		{
			Util::Copy(this->def, def, this->size);
		}

		template<typename T>
		DbVarTmpl(Str_8 id, const T* const def)
			: hashId(id.Hash_64()), id((Str_8&&)id), def(new Byte[sizeof(T)]), size(sizeof(T))
		{
			Util::Copy(this->def, def, this->size);
		}

		DbVarTmpl(Str_8 id);

		DbVarTmpl(DbVarTmpl&& varTmpl) noexcept;

		DbVarTmpl(const DbVarTmpl& varTmpl);

		DbVarTmpl& operator=(DbVarTmpl&& varTmpl) noexcept;

		DbVarTmpl& operator=(const DbVarTmpl& varTmpl);

		operator Byte *() const;

		UInt_64 GetHashId() const;

		void SetId(Str_8 newId);

		Str_8 GetId() const;

		template<typename T>
		T* GetDefaultArray() const
		{
			return (T*)def;
		}

		template<typename T>
		T GetDefault() const
		{
			return *(T*)def;
		}

		UInt_64 GetSize() const;

	private:
		void Serialize(Serializer<UInt_64> &data) const;

		void Deserialize(Serializer<UInt_64> &data);
	};
}