// Copyright ExByte Studios. Item Interaction Ecosystem.

#include "WorldInteractionActions.h"
#include "ItemInteractionComponent.h"
#include "ItemNativeTags.h"
#include "GameFramework/Character.h"

namespace
{
	bool RouteToComponent(const FInteractionContext& Context, EItemInteractionMode Mode, const FGameplayTag& ActionTag)
	{
		if (!Context.Character)
		{
			return false;
		}
		if (UItemInteractionComponent* Comp = Context.Character->FindComponentByClass<UItemInteractionComponent>())
		{
			return Comp->ServerExecuteMode(Context, Mode, ActionTag);
		}
		return false;
	}
}

UInteractionAction_CarryAttached::UInteractionAction_CarryAttached()
{
	ActionTag = ItemEcosystemTags::Action_Carry;
	Mode = EItemInteractionMode::CarryAttached;
	Priority = 500;
	DisplayText = NSLOCTEXT("ItemWorld", "Carry", "Carry");
}
void UInteractionAction_CarryAttached::Execute_Implementation(const FInteractionContext& Context)
{
	RouteToComponent(Context, Mode, ActionTag);
}

UInteractionAction_CarryPhysics::UInteractionAction_CarryPhysics()
{
	ActionTag = ItemEcosystemTags::Action_Carry;
	Mode = EItemInteractionMode::CarryPhysicsHandle;
	Priority = 500;
	DisplayText = NSLOCTEXT("ItemWorld", "CarryPhysics", "Pick Up");
}
void UInteractionAction_CarryPhysics::Execute_Implementation(const FInteractionContext& Context)
{
	RouteToComponent(Context, Mode, ActionTag);
}

UInteractionAction_Equip::UInteractionAction_Equip()
{
	ActionTag = ItemEcosystemTags::Action_Equip;
	Mode = EItemInteractionMode::EquipFromInventory;
	Priority = 800;
	DisplayText = NSLOCTEXT("ItemWorld", "Equip", "Equip");
}
void UInteractionAction_Equip::Execute_Implementation(const FInteractionContext& Context)
{
	RouteToComponent(Context, Mode, ActionTag);
}

UInteractionAction_DropHeldItem::UInteractionAction_DropHeldItem()
{
	ActionTag = ItemEcosystemTags::Action_Drop;
	Mode = EItemInteractionMode::DropHeldItem;
	Priority = 300;
	DisplayText = NSLOCTEXT("ItemWorld", "Drop", "Drop");
}
void UInteractionAction_DropHeldItem::Execute_Implementation(const FInteractionContext& Context)
{
	RouteToComponent(Context, Mode, ActionTag);
}

UInteractionAction_InstallIntoWorldSlot::UInteractionAction_InstallIntoWorldSlot()
{
	ActionTag = ItemEcosystemTags::Action_Install;
	Mode = EItemInteractionMode::InstallIntoWorldSlot;
	Priority = 900;
	DisplayText = NSLOCTEXT("ItemWorld", "Install", "Install");
}
void UInteractionAction_InstallIntoWorldSlot::Execute_Implementation(const FInteractionContext& Context)
{
	RouteToComponent(Context, Mode, ActionTag);
}

UInteractionAction_RemoveFromWorldSlot::UInteractionAction_RemoveFromWorldSlot()
{
	ActionTag = ItemEcosystemTags::Action_Remove;
	Mode = EItemInteractionMode::RemoveFromWorldSlot;
	Priority = 400;
	DisplayText = NSLOCTEXT("ItemWorld", "Remove", "Remove");
}
void UInteractionAction_RemoveFromWorldSlot::Execute_Implementation(const FInteractionContext& Context)
{
	RouteToComponent(Context, Mode, ActionTag);
}

UInteractionAction_UseHeldOnTarget::UInteractionAction_UseHeldOnTarget()
{
	ActionTag = ItemEcosystemTags::Action_UseHeldOnTarget;
	Mode = EItemInteractionMode::UseHeldOnTarget;
	Priority = 800;
	DisplayText = NSLOCTEXT("ItemWorld", "Use", "Use");
}
void UInteractionAction_UseHeldOnTarget::Execute_Implementation(const FInteractionContext& Context)
{
	RouteToComponent(Context, Mode, ActionTag);
}
