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

#include "Components/InworldConversationTargetComponent.h"

FInworldConversationTargetInitialized UInworldConversationTargetComponent::OnInworldConversationTargetInitialized;
FInworldConversationTargetBeginPlay UInworldConversationTargetComponent::OnInworldConversationTargetBeginPlay;
FInworldConversationTargetEndPlay UInworldConversationTargetComponent::OnInworldConversationTargetEndPlay;

UInworldConversationTargetComponent::UInworldConversationTargetComponent(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	bWantsInitializeComponent = true;
	bIsReady = false;
}

void UInworldConversationTargetComponent::InitializeComponent()
{
	Super::InitializeComponent();

	if (Id.IsEmpty())
	{
		Id = FGuid::NewGuid().ToString();
	}

	OnInworldConversationTargetInitialized.Broadcast(this);
}

void UInworldConversationTargetComponent::BeginPlay()
{
	Super::BeginPlay();
	OnInworldConversationTargetBeginPlay.Broadcast(this);
}

void UInworldConversationTargetComponent::EndPlay(EEndPlayReason::Type Reason)
{
	OnInworldConversationTargetEndPlay.Broadcast(this);
	Super::EndPlay(Reason);
}

void UInworldConversationTargetComponent::TrySignalReady()
{
	if (bIsReady)
	{
		return;
	}

	bIsReady = true;
	OnConversationTargetReady.Broadcast(this);
	OnConversationTargetReadyNative.Broadcast(this);
}
