using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTANetworkAPI;
using Newtonsoft.Json;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Inventory.Interfaces;
using ReallifeGamemode.Server.Managers;

namespace ReallifeGamemode.Server.Shop.SevenEleven
{
  public class ItemShop
  {
    public Vector3 vector3;
    public int id;
    public List<ShopItem> shopItems = new List<ShopItem>();

    public ItemShop(Vector3 vector3, int id)
    {
      this.vector3 = vector3;
      this.id = id;
    }

    public void LoadItems()
    {
      using(var dbContext = new DatabaseContext())
      {
        shopItems = dbContext.ShopItems.ToList().FindAll(i => i.ShopId == id);
      }
    }
    public void LoadShopNUI(Player client)
    {
      List<ShopItem> itemList = shopItems.ToList().FindAll(s => s.Amount > 0);
      List<IItem> items = new List<IItem>();
      foreach(var item in itemList)
      {
         items.Add(InventoryManager.GetItemById(item.ItemId));
      }
      client.TriggerEvent("itemMenu:updateData", JsonConvert.SerializeObject(items.ToArray()));
    }
  }
}
