using System;
using System.Collections.Generic;
using System.Linq;
using GTANetworkAPI;
using Newtonsoft.Json;
using ReallifeGamemode.Database.Entities;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Extensions;

namespace ReallifeGamemode.Server.Shop.Clothing
{
  public class ClotheShop
  {
    public int category { get; set; }
    public Vector3 vector { get; set; }
    public List<ShopClothe> clotheList = new List<ShopClothe>();

    public ClotheShop(int category, Vector3 vector)
    {
      this.category = category;
      this.vector = vector;
      LoadClothes();
    }

    public void LoadClothes()
    {
      using (var dbContext = new DatabaseContext())
      {
        clotheList = dbContext.ShopClothes.ToList().FindAll(c => c.Category == category);
      }
    }

    public void LoadShopNUI(Player client)
    {
      bool gender = client.GetUser().GetCharacter().Gender;
      List<ShopClothe> tops = clotheList.ToList().FindAll(c => c.Gender == gender && c.ComponentId == 11);
      List<ShopClothe> legs = clotheList.ToList().FindAll(c => c.Gender == gender && c.ComponentId == 4);
      List<ShopClothe> shoes = clotheList.ToList().FindAll(c => c.Gender == gender && c.ComponentId == 6);
      List<ShopClothe> accessoires = clotheList.ToList().FindAll(c => c.Gender == gender && c.ComponentId == 7);

      List<Array> clothes = new List<Array>
      {
        tops.ToArray(),
        legs.ToArray(),
        shoes.ToArray(),
        accessoires.ToArray()
      };

      client.TriggerEvent("clothesMenu:updateData", JsonConvert.SerializeObject(category), JsonConvert.SerializeObject(clothes.ToArray()), gender);
    }
  }
}
