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

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

using namespace Sourcify;

SCW_FMapProperty::SCW_FMapProperty(FMapProperty* InMapProperty) : SCW_FProperty(InMapProperty), MapProperty(InMapProperty)
{

}

wstring SCW_FMapProperty::GetCPPTypeCustom(wstring* ExtendedTypeText, SCW_EPropertyExportCPPFlags CPPExportFlags, const wstring& KeyTypeText, const wstring& InKeyExtendedTypeText, const wstring& ValueTypeText, const wstring& InValueExtendedTypeText) const
{
	if (ExtendedTypeText == nullptr)
	{
		return *MapProperty->GetCPPTypeCustom(nullptr, static_cast<uint32>(CPPExportFlags), KeyTypeText.c_str(), InKeyExtendedTypeText.c_str(), ValueTypeText.c_str(), InValueExtendedTypeText.c_str());
	}

	FString ExtendedTypeTextFString = ExtendedTypeText->c_str();
	FString CPPTypeCustomFString = MapProperty->GetCPPTypeCustom(&ExtendedTypeTextFString, static_cast<uint32>(CPPExportFlags), KeyTypeText.c_str(), InKeyExtendedTypeText.c_str(), ValueTypeText.c_str(), InValueExtendedTypeText.c_str());
	*ExtendedTypeText = *ExtendedTypeTextFString;
	
	return *CPPTypeCustomFString;
}

ISCW_FPropertyPtr SCW_FMapProperty::GetKeyProperty() const
{
	return FSourcifyCoreUEWrapper::Get().Wrap(*MapProperty->KeyProp);
}

ISCW_FPropertyPtr SCW_FMapProperty::GetValueProperty() const
{
	return FSourcifyCoreUEWrapper::Get().Wrap(*MapProperty->ValueProp);
}

FMapProperty* SCW_FMapProperty::ToFMapProperty() const
{
	return MapProperty;
}
