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


#include "ExposeBodyPartRestriction.h"

#include "NakedDesire/Clothing/ClothingItemDefinition.h"
#include "NakedDesire/Clothing/ClothingItemInstance.h"
#include "NakedDesire/Player/NakedDesireCharacter.h"
#include "NakedDesire/Clothing/ClothingManager.h"

#define LOCTEXT_NAMESPACE "Missions.Restrictions.ExposeBodyPart"
const FText RestrictionsExposeBodyPartDescription = LOCTEXT("Description", "Expose {BodyPart}");
#undef LOCTEXT_NAMESPACE

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

	PlayerCharacter->ClothingManager->OnClothingEquip.AddUniqueDynamic(this, &UExposeBodyPartRestriction::EquipClothing);
	PlayerCharacter->ClothingManager->OnClothingUnequip.AddUniqueDynamic(this, &UExposeBodyPartRestriction::UnequipClothing);

	CheckClothing();
}

void UExposeBodyPartRestriction::Stop()
{
	Super::Stop();

	Player->ClothingManager->OnClothingEquip.Remove(this, TEXT("ClothingEquip"));
	Player->ClothingManager->OnClothingUnequip.Remove(this, TEXT("ClothingUnequip"));
}

FText UExposeBodyPartRestriction::GetDescription() const
{
	FText BodyPartString;
	switch (BodyPart)
	{
	case EBodyPart::Ass:
		BodyPartString = FText::FromString("Ass");
		break;
	case EBodyPart::Boobs:
		BodyPartString = FText::FromString("Boobs");
		break;
	case EBodyPart::Genitals:
		BodyPartString = FText::FromString("Genitals");
		break;
	default:
		BodyPartString = FText::FromString("None");
		break;
	}
	
	return FText::Format(RestrictionsExposeBodyPartDescription,
		FFormatNamedArguments
		{
			{TEXT("BodyPart"), BodyPartString}
		});
}

void UExposeBodyPartRestriction::EquipClothing(UClothingItemInstance* ClothingItemInstance)
{
	if (IsSuccess) // TODO: Add covered body part resolution
	{
		Init(Player);
	}
}

void UExposeBodyPartRestriction::UnequipClothing(UClothingItemInstance* ClothingItemInstance)
{
	if (IsSuccess)
		return;

	CheckClothing();
}

void UExposeBodyPartRestriction::CheckClothing()
{
	// if (!Player || !Player->ClothingManager || Player->ClothingManager->ClothingSlots.IsEmpty())
	// {
	// 	return;
	// }
	//
	// const FClothingSlotData* TargetClothingItem = Player->ClothingManager->ClothingSlots.FindByPredicate([this](const FClothingSlotData& ClothingSlot)
	// {
	// 	if (ClothingSlot.ClothingItemInstance)
	// 	{
	// 		return true; // TODO: Add exposed body part resolution
	// 	}
	//
	// 	return false;
	// });
	// if (!TargetClothingItem)
	// {
	// 	Complete();
	// }
}
