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

#include "SCW_FObjectProperty.h"

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

using namespace Sourcify;

SCW_FObjectProperty::SCW_FObjectProperty(FObjectProperty* InObjectProperty) : SCW_FObjectPropertyBase(InObjectProperty), ObjectProperty(InObjectProperty)
{

}
ISCW_UObjectPtr SCW_FObjectProperty::GetObjectPropertyValue_InContainer(shared_ptr<const ISCW_UObject> ContainerAddress, int32_t ArrayIndex/* = 0*/) const
{
	if (UObject* objectValue = ObjectProperty->GetObjectPropertyValue_InContainer(dynamic_cast<const SCW_UObject*>(ContainerAddress.get())->ToUObjectRawPtr(), ArrayIndex))
	{
		return FSourcifyCoreUEWrapper::Get().Wrap(*objectValue);
	}
	return nullptr;
}

ISCW_UObjectPtr SCW_FObjectProperty::GetPropertyValue_InContainer(shared_ptr<const ISCW_UObject> ContainerAddress, int32_t ArrayIndex/* = 0*/) const
{
	if (UObject* objectValue = ObjectProperty->GetPropertyValue_InContainer(dynamic_cast<const SCW_UObject*>(ContainerAddress.get())->ToUObjectRawPtr(), ArrayIndex))
	{
		return FSourcifyCoreUEWrapper::Get().Wrap(*objectValue);
	}
	return nullptr;
}

void SCW_FObjectProperty::SetPropertyValue_InContainer(shared_ptr<ISCW_UObject> A, ISCW_UObjectConstPtr Value, int32_t ArrayIndex/* = 0*/) const
{
	ObjectProperty->SetPropertyValue_InContainer(dynamic_cast<SCW_UObject*>(A.get())->ToUObjectRawPtr(), dynamic_cast<const SCW_UObject*>(Value.get())->ToUObjectRawPtr(), ArrayIndex);
}

FObjectProperty* SCW_FObjectProperty::ToFObjectProperty() const
{
	return ObjectProperty;
}
