using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public enum Equipment
{
    NONE,
    CrystalBall,
    Candle,
    Gravestone
}

[System.Serializable]
public class InventoryItem
{
    public InventoryItem(Equipment type, bool limited, int startCount)
    {
        m_Type = type;
        m_IsLimited = limited;
        m_Count = startCount;
    }
    public Equipment m_Type = Equipment.NONE;
    public bool m_IsLimited = false;
    public int m_Count = -1;
    public AudioClip m_UseClip;
    public Sprite m_ItemSprite;
}

public class InventoryManager : MonoBehaviour
{
    public System.Action<Equipment> ChangeEquipment;

    public List<InventoryItem> m_Inventory = new List<InventoryItem>();

    public InventoryItem CurrentEquipment {
        get {
            return m_Inventory[m_CurrentEquipment];
        }
    }

    [SerializeField] private AudioClip m_SelectEquipment;

    private int m_CurrentEquipment = 0;

    void SwapEquipment(int direction)
    {
        m_CurrentEquipment += direction;
        m_CurrentEquipment = Repeat(m_CurrentEquipment, m_Inventory.Count - 1);
        ChangeEquipment(m_Inventory[m_CurrentEquipment].m_Type);
    }

   /* void InitialiseInventory()
    {
        m_Inventory.Add(new InventoryItem(Equipment.CrystalBall, false, 1));
        m_Inventory.Add(new InventoryItem(Equipment.Candle, true, 10));
        m_Inventory.Add(new InventoryItem(Equipment.Gravestone, true, 5));
    }*/

    public void UseEquipment()
    {
        CurrentEquipment.m_Count--;        
        SoundManager.PlayOneShot(m_SelectEquipment);
    }

    // Start is called before the first frame update
    void Start()
    {
        //InitialiseInventory();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
            SwapEquipment(1);
    }

    int Repeat(int t, int length, int min = 0)
    {
        if (t > length)
            return min;
        if (t < 0)
            return length;
        return t;
    }
}


