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


#include "ReachEmbarrassmentObjective.h"

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

#define LOCTEXT_NAMESPACE "Commissions.Objectives.ReachEmbarrassment"

void UReachEmbarrassmentObjective::OnActivate()
{
	if (Player && Player->StatsManager)
		Player->StatsManager->EmbarrassmentUpdate.AddDynamic(this, &UReachEmbarrassmentObjective::HandleEmbarrassmentUpdate);
}

void UReachEmbarrassmentObjective::OnDeactivate()
{
	if (Player && Player->StatsManager)
		Player->StatsManager->EmbarrassmentUpdate.RemoveDynamic(this, &UReachEmbarrassmentObjective::HandleEmbarrassmentUpdate);
}

bool UReachEmbarrassmentObjective::IsConditionMet() const
{
	return CachedMax > 0.0f && CachedCurrent >= ThresholdFraction * CachedMax;
}

void UReachEmbarrassmentObjective::HandleEmbarrassmentUpdate(float CurrentValue, float MaxValue)
{
	CachedCurrent = CurrentValue;
	CachedMax = MaxValue;
	NotifyConditionChanged();
}

FText UReachEmbarrassmentObjective::GetDescription() const
{
	const FText Percent = FText::AsNumber(FMath::RoundToInt(ThresholdFraction * 100.0f));

	if (RequiredHoldSeconds > 0.0f)
	{
		return FText::Format(LOCTEXT("Timed", "Keep embarrassment above {0}% for {1} seconds"),
			Percent, FText::AsNumber(FMath::RoundToInt(RequiredHoldSeconds)));
	}

	return FText::Format(LOCTEXT("Instant", "Push your embarrassment past {0}%"), Percent);
}

#undef LOCTEXT_NAMESPACE