// Copyright (c) 2024 Codemongous LLC. All Rights Reserved.

#include "SCW_FField.h"
#include "CoreMinimal.h"
#include "UObject/Field.h"
#include "SourcifyCoreUEWrapperModule.h"

using namespace Sourcify;

SCW_FField::SCW_FField(FField* InField) : Field(InField)
{

}

bool SCW_FField::GetBoolMetaData(const wstring& Key) const
{
	return Field->GetBoolMetaData(WCHAR_TO_TCHAR(Key.c_str()));
}

map<wstring, wstring> SCW_FField::GetMetaDataMap() const
{
	map<wstring, wstring> MetaData;
	if (const TMap<FName, FString>* MetaDataMap = Field->GetMetaDataMap())
	{
		for (const auto& MetaDataPair : *MetaDataMap)
		{
			MetaData.emplace(*MetaDataPair.Key.ToString(), *MetaDataPair.Value);
		}
	}
	return MetaData;
}

bool SCW_FField::IsNative() const
{
	return Field->IsNative();
}

bool SCW_FField::Less(const ISCW_FField& Other) const
{
	return Field < dynamic_cast<const SCW_FField&>(Other).Field;
}

bool SCW_FField::ISCW_Equals(const ISCW_FField& Other) const
{
	return Field == dynamic_cast<const SCW_FField&>(Other).Field;
}

bool SCW_FField::ISCW_Equals(const shared_ptr<const ISCW_FField> Other) const
{
	return Field == dynamic_cast<const SCW_FField&>(*Other).Field;
}

size_t SCW_FField::GetHash() const
{
	return std::hash<FField*>{}(Field);
}

FField* SCW_FField::ToFField() const
{
	return Field;
}

ISCW_FFieldPtr SCW_FField::ToFFieldPtr()
{
	return GetSharedThisAs<SCW_FField>();
}

ISCW_FFieldConstPtr SCW_FField::ToFFieldPtr() const
{
	return GetSharedThisAs<SCW_FField>();
}
