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

#include "SCW_FEdGraphPinType.h"
#include "EdGraph/EdGraphPin.h"
#include "SCW_UObject.h"
#include "SourcifyCoreUEWrapperModule.h"

using namespace Sourcify;

SCW_FEdGraphPinType::SCW_FEdGraphPinType(FEdGraphPinType* InEdGraphPinType) : EdGraphPinType(InEdGraphPinType)
{

}

SCW_EPinContainerType SCW_FEdGraphPinType::GetContainerType() const
{
	return static_cast<SCW_EPinContainerType>(GetInternalPinType()->ContainerType);
}

wstring SCW_FEdGraphPinType::GetPinCategory() const
{
	return *GetInternalPinType()->PinCategory.ToString();
}
		
wstring SCW_FEdGraphPinType::GetPinSubCategory() const
{
	return *GetInternalPinType()->PinSubCategory.ToString();
}

ISCW_UObjectPtr SCW_FEdGraphPinType::GetPinSubCategoryObject() const
{
	return GetInternalPinType()->PinSubCategoryObject.IsValid() ? FSourcifyCoreUEWrapper::Get().Wrap(*GetInternalPinType()->PinSubCategoryObject) : nullptr;
}

void SCW_FEdGraphPinType::SetPinCategory(const wstring& InCategory) const
{
	GetInternalPinType()->PinCategory = FName(InCategory.c_str());
}
		
void SCW_FEdGraphPinType::SetPinSubCategory(const wstring& InSubCategory) const
{
	GetInternalPinType()->PinSubCategory = FName(InSubCategory.c_str());
}

void SCW_FEdGraphPinType::SetPinSubCategoryObject(ISCW_UObjectPtr InObjectPtr) const
{
	GetInternalPinType()->PinSubCategoryObject = dynamic_cast<SCW_UObject*>(InObjectPtr.get())->ToUObjectRawPtr();
}

ISCW_FSimpleMemberReferencePtr SCW_FEdGraphPinType::GetPinSubCategoryMemberReference() const
{
	return FSourcifyCoreUEWrapper::Get().Wrap(GetInternalPinType()->PinSubCategoryMemberReference);
}

ISCW_FEdGraphTerminalTypePtr SCW_FEdGraphPinType::GetPinValueType() const
{
	return FSourcifyCoreUEWrapper::Get().Wrap(GetInternalPinType()->PinValueType);
}

bool SCW_FEdGraphPinType::IsWeakPointer() const
{
	return GetInternalPinType()->bIsWeakPointer;
}

void SCW_FEdGraphPinType::MakeReadOnlyCopy()
{
	EdGraphPinType = *GetInternalPinType();
}

FEdGraphPinType* SCW_FEdGraphPinType::ToFEdGraphPinType() const
{
	return GetInternalPinType();
}

ISCW_FEdGraphPinTypePtr SCW_FEdGraphPinType::ToFEdGraphPinTypePtr()
{
	return GetSharedThisAs<SCW_FEdGraphPinType>();
}

ISCW_FEdGraphPinTypeConstPtr SCW_FEdGraphPinType::ToFEdGraphPinTypePtr() const
{
	return GetSharedThisAs<SCW_FEdGraphPinType>();
}

FEdGraphPinType* SCW_FEdGraphPinType::GetInternalPinType() const
{
	if (std::holds_alternative<FEdGraphPinType*>(EdGraphPinType))
	{
		return std::get<FEdGraphPinType*>(EdGraphPinType);
	}

	return &const_cast<FEdGraphPinType&>(std::get<FEdGraphPinType>(EdGraphPinType));
}