using Godot;
using System;
using System.Diagnostics;
using System.Linq;
using Cirno.Scripts;
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Godot.Collections;

public partial class Interactable : Area2D, IInteractable
{
	[Export] public Array<LootItem> Requirements = [];
	
	//protected InventoryManager _inventoryManager;
	
	public override void _Ready()
	{
		//_inventoryManager = this.GetInventoryManager();
		//CallDeferred(MethodName.DeferredInitReferences);
	}

	// private void DeferredInitReferences()
	// {
	// 	_inventoryManager = InventoryManager.Instance;
	// }

	protected bool MeetsRequirements()
	{
		if (Requirements.Any())
		{
			if (InventoryManager.Instance.HasItems(Requirements.Select(x => x.ItemKey.ToString()).ToList()))
			{
				GD.Print($"Requirements for activation of {this.Name} successfully met: {string.Join(",", Requirements.Select(x => x.Item))} ");
				return true;
			}
			else
			{
				GD.Print($"Requirements for activation of {this.Name} not met: {string.Join(",", Requirements.Select(x => x.Item))} ");
				return false;
			}
			
		}

		return true;
	}

	public virtual bool Activate(ActivationType activationType = ActivationType.Toggle)
	{
		return true;
	}

	public virtual bool CanActivate()
	{
		return true;
	}
}
