using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

public class EquipmentDataListManager : DataListManager<IndexValuePair<int, EquippableItem>>
{
    public new DataListManager<IndexValuePair<int, EquippableItem>> SetUiManager(ref EquipmentUIManager _uiManager)
    {
        uiManager = _uiManager;

        return this;
    }

    /// <summary>
    /// Function to init equipment list
    /// We should init this before each operation on equipment 
    /// </summary>
    /// <returns></returns>
    public List<IndexValuePair<int, EquippableItem>> InitEquipment()
    {
        List<IndexValuePair<int, EquippableItem>> convertedList = new List<IndexValuePair<int, EquippableItem>>();

        foreach (EquipmentPanelSlotsTypeEnum emptyElement in Enum.GetValues(typeof(EquipmentPanelSlotsTypeEnum))) { convertedList.Add(new IndexValuePair<int, EquippableItem>((int)emptyElement, null)); }

        return convertedList;
    }

    public override void AddElementToList(IndexValuePair<int, EquippableItem> newElement)
    {
        Elements
            .Where(equipment => equipment.Key == newElement.Key)
            .ToList()
            .ForEach(equipment => equipment.Value = newElement.Value);
        
    }

    public override void RemoveElementFromList(IndexValuePair<int, EquippableItem> element)
    {
        Elements
            .Where(equipment => equipment.Key == element.Key)
            .ToList()
            .ForEach(equipment => equipment.Value = null);
    }
}