// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"

typedef uint32 HashValue;

/// \brief a hashed text identifier
/// the hash is presumed to be collision free
/// \remarks if there however is a collision, this has to be assured by the user. The hash is 32bit enforced 
class EVENTMANAGERDEMO_API Identifier
{
public:
	/// creates an identifier
	Identifier() {};

	/// creates an identifier from a string
	/// \param name		identifier name; case will be ignored!
	Identifier(const FString& name);

	/// copy constructor
	Identifier(const Identifier& cpy);

	/// creates an identifier from hash only
	/// \attention the name will bei invalid! only use if the original name is lost
	explicit Identifier(HashValue hash, const FString& identifier = "____unkown identifier name___");

	/// returns clear text name
	FString getName() const { return m_name; }

	/// returns hash-value
	unsigned int getHash() const { return m_hash; }

	/// equality operator
	/// \attention only checks the hash!
	bool operator==(const Identifier& left) const { return m_hash == left.m_hash; }

	/// comparision operator
	/// \attention only checks the hash!
	bool operator<(const Identifier& left) const { return m_hash < left.m_hash; }

	/// typecast to size_t for the unordered containers
	operator size_t() const { return m_hash; }

private:
	FString			m_name;
	HashValue		m_hash;
};

FORCEINLINE uint32 GetTypeHash(const Identifier& id)
{
	return id.getHash();
}