// © 2025 Naked People Team. All Rights Reserved.


#include "ObservedConstraint.h"

#include "NakedDesire/Player/NakedDesireCharacter.h"
#include "NakedDesire/Stats/StatsManager.h"

#define LOCTEXT_NAMESPACE "Commissions.Constraints.Observed"

void UObservedConstraint::OnActivate()
{
	if (Player && Player->StatsManager)
		Player->StatsManager->OnObserversChanged.AddUniqueDynamic(this, &UObservedConstraint::HandleObserversChanged);
}

void UObservedConstraint::OnDeactivate()
{
	if (Player && Player->StatsManager)
		Player->StatsManager->OnObserversChanged.RemoveDynamic(this, &UObservedConstraint::HandleObserversChanged);
}

bool UObservedConstraint::IsMet() const
{
	if (!Player || !Player->StatsManager)
		return false;

	return Player->StatsManager->GetObserverCount() >= MinObservers;
}

void UObservedConstraint::HandleObserversChanged()
{
	NotifyChanged();
}

FText UObservedConstraint::GetDescription() const
{
	return (MinObservers == 1)
		? LOCTEXT("Single", "while someone is watching")
		: FText::Format(LOCTEXT("Multiple", "while {0} people are watching"), FText::AsNumber(MinObservers));
}

#undef LOCTEXT_NAMESPACE