// Copyright CodeSpartan, 2023. All rights reserved.

#pragma once

#include "CoreMinimal.h"
#include "Engine/StreamableManager.h"
#include "JsonObjectWrapper.h"
#include "Kismet/BlueprintAsyncActionBase.h"
#include "Templates/SubclassOf.h"
#include "AsyncLoadPersistentClass.generated.h"

UDELEGATE(BlueprintAuthorityOnly)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FAsyncLoadPersistentOutputPin, TSubclassOf<UObject>, Class, const int32, ObjectId, const FJsonObjectWrapper&, JsonObject);

UCLASS()
class MMOKITCODE_API UAsyncLoadPersistentClass : public UBlueprintAsyncActionBase
{
	GENERATED_UCLASS_BODY()
	
public:
	UPROPERTY(BlueprintAssignable)
	FAsyncLoadPersistentOutputPin Completed;

	/* A Blueprint node that loads a class asynchronously and stores some info temporarily */
	UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject"), Category = "Utilities")
	static UAsyncLoadPersistentClass* AsyncLoadPersistentClass(UObject* WorldContextObject, const TSoftClassPtr<UObject> AssetClass, const int32 ObjectId, const FJsonObjectWrapper& JsonObject);

	// UBlueprintAsyncActionBase interface
	virtual void Activate() override;
	//~UBlueprintAsyncActionBase interface

private:

	UFUNCTION()
	void OnClassAssetLoaded();

	/* Blueprint Node Inputs Below */

	UPROPERTY()
	TSoftClassPtr<UObject> AssetClass;

	UPROPERTY()
	int32 ObjectId;

	UPROPERTY()
	FJsonObjectWrapper JsonObject;
};
