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


#include "FlashGoal.h"

#include "NakedDesire/NPC/NPCAIController.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"

#define LOCTEXT_NAMESPACE "Missions.Goals.Flash"
const FText GoalsFlashSingle = LOCTEXT("Description.Single", "Flash someone {BodyPart} once");
const FText GoalsFlashMultiple = LOCTEXT("Description.Multiple", "Flash {BodyPart} to {PeopleCount} people");
#undef LOCTEXT_NAMESPACE

void UFlashGoal::Init(ANakedDesireCharacter* PlayerCharacter)
{
	Super::Init(PlayerCharacter);

	PlayerNoticedHandle = PlayerCharacter->OnNoticed.AddUObject(this, &UFlashGoal::OnPlayerNoticed);
}

void UFlashGoal::Complete()
{
	Super::Complete();
	
	Player->OnNoticed.Remove(PlayerNoticedHandle);
}

FText UFlashGoal::GetDescription() const
{
	FText BodyTypeString;

	switch (BodyType)
	{
	case EBodyPart::Ass:
		BodyTypeString = FText::FromString("Ass");
		break;
	case EBodyPart::Boobs:
		BodyTypeString = FText::FromString("Boobs");
		break;
	case EBodyPart::Genitals:
		BodyTypeString = FText::FromString("Genitals");
		break;
	default:
		BodyTypeString = FText::FromString("None");
		break;
	}
	
	if (RequiredFlashCount == 1)
	{
		return FText::Format(GoalsFlashSingle,
			FFormatNamedArguments
			{
				{TEXT("BodyPart"), BodyTypeString}
			});
	}
	
	return FText::Format(GoalsFlashMultiple,
		FFormatNamedArguments
		{
			{TEXT("BodyPart"), BodyTypeString},
			{TEXT("PeopleCount"), RequiredFlashCount}
		});
}

void UFlashGoal::OnPlayerNoticed(ANPCAIController* NPC)
{
	if (IsCompleted || !CheckRestrictions())
	{
		return;
	}

	if (!NoticedActors.Contains(NPC))
	{
		NoticedActors.Add(NPC);
	}

	if (NoticedActors.Num() >= RequiredFlashCount)
	{
		Complete();
	}
}
