// Copyright ExByte Studios. Item Interaction Ecosystem.

#pragma once

#include "CoreMinimal.h"
#include "GameplayTagContainer.h"
#include "ItemLockData.generated.h"

/**
 * Server-side soft lock placed on an item while a transaction owns it (section 20).
 * Prevents dupes / conflicts: a locked item cannot be moved, taken, dropped,
 * crafted, deleted or stacked by anyone but the locking actor.
 */
USTRUCT(BlueprintType)
struct ITEMCORE_API FItemLockData
{
	GENERATED_BODY()

	UPROPERTY(BlueprintReadOnly, Category = "Item|Lock")
	bool bLocked = false;

	/** Lock.Carrying / Lock.Using / Lock.Transferring / ... */
	UPROPERTY(BlueprintReadOnly, Category = "Item|Lock")
	FGameplayTag LockReason;

	UPROPERTY(BlueprintReadOnly, Category = "Item|Lock")
	TWeakObjectPtr<AActor> LockedBy;

	/** Server world time (seconds) at which the lock auto-expires; 0 = no expiry. */
	UPROPERTY(BlueprintReadOnly, Category = "Item|Lock")
	float LockExpireTime = 0.f;

	bool IsLockedBy(const AActor* Actor) const { return bLocked && LockedBy.Get() == Actor; }

	void Clear()
	{
		bLocked = false;
		LockReason = FGameplayTag();
		LockedBy = nullptr;
		LockExpireTime = 0.f;
	}
};
