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

#include "SCW_FMetaData.h"

#if ISCW_UE_VERSION_NEWER_THAN_OR_EQUAL(5, 6, 0)

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

using namespace Sourcify;

SCW_FMetaData::SCW_FMetaData(FMetaData* InMetaData) : MetaData(InMetaData)
{

}

FMetaData* SCW_FMetaData::ToFMetaData() const
{
	return MetaData;
}

ISCW_FMetaDataPtr SCW_FMetaData::ToFMetaDataPtr()
{
	return GetSharedThisAs<SCW_FMetaData>();
}

ISCW_FMetaDataConstPtr SCW_FMetaData::ToFMetaDataConstPtr() const
{
	return GetSharedThisAs<SCW_FMetaData>();
}

wstring SCW_FMetaData::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_FMetaData::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 // ISCW_UE_VERSION_NEWER_THAN_OR_EQUAL(5, 6, 0)