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.Friseur
{
  public class Friseur
  {
    public int category { get; set; }
    public Vector3 vector { get; set; }
    public List<ShopClothe> frisurList = new List<ShopClothe>();

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

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

    public void LoadShopNUI(Player client)
    {
      User u = client.GetUser();

      if (u == null)
      {
        return;
      }

      bool gender = u.GetCharacter().Gender;

      List<ShopClothe> frisur = frisurList.ToList().FindAll(c => c.Gender == gender && c.ComponentId == 2);

      List<Array> frisuren = new List<Array>
      {
        frisur.ToArray()
      };

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


    

  }
}
