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

#include "SCW_UMetaData.h"
// UMetaData is deprecated as of 5.6, use FMetaData instead.
#if ISCW_UE_VERSION_OLDER_THAN(5, 6, 0)

#include "UObject/MetaData.h"
#include "SourcifyCoreUEWrapperModule.h"
#include "SCW_UObject.h"

using namespace Sourcify;

SCW_UMetaData::SCW_UMetaData(UMetaData* InMetaData) : SCW_UObject(InMetaData), MetaData(InMetaData)
{

}

UMetaData* SCW_UMetaData::ToUMetaData() const
{
	return MetaData;
}

ISCW_UMetaDataPtr SCW_UMetaData::ToUMetaDataPtr()
{
	return GetSharedThisAs<SCW_UMetaData>();
}

ISCW_UMetaDataConstPtr SCW_UMetaData::ToUMetaDataConstPtr() const
{
	return GetSharedThisAs<SCW_UMetaData>();
}

wstring SCW_UMetaData::GetValue(ISCW_UObjectConstPtr InObject, const wstring& Key) const
{
	const SCW_UObject* SCWObject = dynamic_cast<const SCW_UObject*>(InObject.get());
	return *MetaData->GetValue(SCWObject->ToUObjectRawPtr(), Key.c_str());
}

void SCW_UMetaData::SetValue(ISCW_UObjectPtr InObject, const wstring& Key, const wstring& Value)
{
	SCW_UObject* SCWObject = dynamic_cast<SCW_UObject*>(InObject.get());
	MetaData->SetValue(SCWObject->ToUObjectRawPtr(), Key.c_str(), Value.c_str());
}

#endif // #if ISCW_UE_VERSION_OLDER_THAN(5, 6)