using System.Collections.Generic;
using System.Linq;
using GTANetworkAPI;
using ReallifeGamemode.Database.Entities.Saves;
using ReallifeGamemode.Database.Models;
using ReallifeGamemode.Server.Shop.Clothing;
using ReallifeGamemode.Server.Shop.SevenEleven;
using ReallifeGamemode.Server.Shop.Friseur;
using ReallifeGamemode.Server.Shop.Ammunation;

namespace ReallifeGamemode.Server.Managers
{
  public class ShopManager
  {
    public static List<ClotheShop> clotheStores = new List<ClotheShop>();
    public static List<ItemShop> itemShops = new List<ItemShop>();
    public static List<Friseur> FriseurStores = new List<Friseur>();
    public static List<Ammunation> Ammunations = new List<Ammunation>();

    public static void LoadClotheShops()
    {
      using (var dbContext = new DatabaseContext())
      {
        List<SavedBlip> discount = dbContext.Blips.ToList().FindAll(s => s.Name == "Binco" || s.Name == "Discount Store");
        List<SavedBlip> midclass = dbContext.Blips.ToList().FindAll(s => s.Name == "Suburban");
        List<SavedBlip> luxury = dbContext.Blips.ToList().FindAll(s => s.Name == "Ponsonbys");

        foreach (var store in discount)
        {
          Vector3 pos = new Vector3(store.PositionX, store.PositionY, store.PositionZ);
          ClotheShop newShop = new ClotheShop(1, pos);
          clotheStores.Add(newShop);
          NAPI.Util.ConsoleOutput($"Loading ClotheShop {store.Name}");
        }
        foreach (var store in midclass)
        {
          Vector3 pos = new Vector3(store.PositionX, store.PositionY, store.PositionZ);
          ClotheShop newShop = new ClotheShop(2, pos);
          clotheStores.Add(newShop);
          NAPI.Util.ConsoleOutput($"Loading ClotheShop {store.Name}");
        }
        foreach (var store in luxury)
        {
          Vector3 pos = new Vector3(store.PositionX, store.PositionY, store.PositionZ);
          ClotheShop newShop = new ClotheShop(3, pos);
          clotheStores.Add(newShop);
          NAPI.Util.ConsoleOutput($"Loading ClotheShop {store.Name}");
        }
      }
    }

    public static void LoadItemShops()
    {
      using (var dbContext = new DatabaseContext())
      {
        int id = 0;
        List<SavedBlip> shops = dbContext.Blips.ToList().FindAll(s => s.Name == "24/7");
        foreach (var store in shops)
        {
          Vector3 pos = new Vector3(store.PositionX, store.PositionY, store.PositionZ);
          ItemShop newShop = new ItemShop(pos, id);
          itemShops.Add(newShop);
          id++;
        }
        NAPI.Util.ConsoleOutput($"Loaded {itemShops.Count}x 24/7");
      }
    }

    public static void LoadFriseur()
    {
      using (var dbContext = new DatabaseContext())
      {
        List<SavedBlip> friseur = dbContext.Blips.ToList().FindAll(s => s.Name == "Friseur");

        
        foreach (var store in friseur)
        {
          Vector3 pos = new Vector3(store.PositionX, store.PositionY, store.PositionZ);
          Friseur newShop = new Friseur(10, pos);
          FriseurStores.Add(newShop);
          NAPI.Util.ConsoleOutput($"Loading Friseur {store.Name}");
        }
      }
    }

    public static void LoadAmmunations()
    {
      using (var dbContext = new DatabaseContext())
      {
        List<SavedBlip> ammunations = dbContext.Blips.ToList().FindAll(s => s.Name == "Ammunation");

        foreach (var store in ammunations)
        {
          Vector3 pos = new Vector3(store.PositionX, store.PositionY, store.PositionZ);
          Ammunation newShop = new Ammunation(pos);
          Ammunations.Add(newShop);
        }
        NAPI.Util.ConsoleOutput($"Loading {ammunations.Count} Ammunations");
      }
    }
  }
}
