#pragma once

#include "CoreMinimal.h"
#include "Identifier.h"
#include "IEvent.h"

class DemoEvent : public IEvent
{
public:
	DemoEvent(int oldValue, int newValue)
	{
		m_oldValue = oldValue;
		m_newValue = newValue;
	}
	DemoEvent() {}
	~DemoEvent() {}

	static const unsigned int Identity = 515189911;
	HashValue getHash() const override
	{
		return Identity;
	}

	FString getName() const override
	{
		return FString("DemoEvent");
	}

	int getOldValue() const
	{
		return m_oldValue;
	}

	int getNewValue() const
	{
		return m_newValue;
	}

private:
	virtual void serializeBiDirectional(FString& data, bool write) override
	{
		if (!write)
		{
			int32 found = data.Find("#|#");
			if (found != INDEX_NONE)
			{
				m_oldValue = FCString::Atoi(*data.Mid(0, found));
				data = data.Mid(found + 3);
			}

			int32 found2 = data.Find("#|#");
			if (found2 != INDEX_NONE)
			{
				m_newValue = FCString::Atoi(*data.Mid(0, found2));
				data = data.Mid(found2 + 3);
			}
		}
		else
		{
			data.Append(FString::FromInt(m_oldValue));
			data.Append("#|#");
			data.Append(FString::FromInt(m_newValue));
			data.Append("#|#");
		}
	}

	int m_oldValue;
	int m_newValue;
};

REGISTER_EVENT(DemoEvent);