using System.Linq;
using Cirno.Scripts.Resources;
using Cirno.Scripts.UI;
using Godot;
using Godot.Collections;

namespace Cirno.Scripts.Actors;

public partial class VendingMachine : Interactable
{

    [Export] public bool Infinite { get; private set; } = false;
    
    [Export] public PackedScene UiScene { get; private set; }
    
    [Export] public Array<LootItem> Items { get; set; }

    
    public override bool Activate(ActivationType activationType = ActivationType.Toggle)
    {
        GameManager.Instance.ChangeState(GameState.Shop);

        var ui = UiScene.Instantiate<VendingMachineUi>();

        ui.Machine = this;

        ui.Items = new LootItem[3];
        int i = 0;
        foreach (var item in Items)
        {
            ui.Items[i] = item;
            i++;
        }
        
        
        this.AddChild(ui);
        
        return true;
    }
}