using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;

[Serializable]
public class ShopBuildModel
{
    [NonSerialized] public string ShopName;  // npc name

    [SerializeField] public List<IndexValuePair<Item>> Content = new List<IndexValuePair<Item>>();

    public ShopBuildModel(string ownerName, List<IndexValuePair<EquippableItem>> shopContent)
    {
        ShopName = ownerName;


        Content.Clear();
        foreach (IndexValuePair<EquippableItem> item in shopContent)
        {
            Content.Add(
                new IndexValuePair<Item>(item.Key, item.Value)
            );
        }
    }

    public Shop MapBuildModelToShop()
    {
        var shop = new Shop(
            SceneManager.GetActiveScene().name,
            ShopName
        );

        shop.Content = new List<IndexValuePair<int, EquippableItem>>();

        foreach (var ChestElement in Content)
        {
            var castedObject = ChestElement.Value as EquippableItem;

            if (castedObject == null)
                shop.Content.Add(
                    new IndexValuePair<int, EquippableItem>(ChestElement.Key, new EquippableItem(ChestElement.Value))
                );
            else
                shop.Content.Add(
                    new IndexValuePair<int, EquippableItem>(ChestElement.Key, castedObject)
                );
        }

        return shop;
    }
}