using System.Linq;
using Cirno.Scripts.Controllers;

namespace Cirno.Scripts.Interactables;

public partial class RogueliteDoorLock : Switch
{
    public RoomConnection Connection { get; set; }

    public override bool Activate(ActivationType activationType = ActivationType.Toggle)
    {
        base.Activate(activationType);
        
        if (!MeetsRequirements()) return false;

        Connection.FromDoor.Activate(activationType);
        Connection.ToDoor.Activate(activationType);

        foreach (var requirement in Requirements)
        {
            InventoryManager.Instance.RemoveItem(requirement.ItemKey, 1);
        }
        
        
        this.QueueFree();
        
        return true;
    }
}