/**
 * Copyright 2022-2025 Theai, Inc. dba Inworld AI
 */
#pragma once

#include "CoreMinimal.h"
#include "EdGraph/EdGraph.h"

#include "EdGraph_InworldGraph.generated.h"

class UInworldGraphAsset;
class UInworldNodeAsset;
class UInworldEdgeAsset;
class UInworldGraphRuntimeData;
class UEdNode_InworldGraphNode;
class UEdNode_InworldGraphEdge;

UCLASS()
class INWORLDRUNTIMEEDITOR_API UEdGraph_InworldGraph : public UEdGraph
{
	GENERATED_BODY()

public:
	static void RefreshOpenedAssets();

	void RebuildInworldGraph();
	void RebuildEditorGraph();
	void ValidateGraph(bool bWithNotification = true);

	UInworldGraphAsset* GetInworldGraph() const;

	virtual bool Modify(bool bAlwaysMarkDirty = true) override;
	virtual void PostEditUndo() override;
	virtual void PreSave(FObjectPreSaveContext SaveContext) override;
	
	UPROPERTY(Transient)
	TMap<UInworldNodeAsset*, UEdNode_InworldGraphNode*> NodeMap;

	UPROPERTY(Transient)
	TMap<UInworldEdgeAsset*, UEdNode_InworldGraphEdge*> EdgeMap;

protected:
	void Clear();
	void SortNodes(TArray<UInworldNodeAsset*> RootNodes);
};
