using Example.Connectors;
using Example.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Example.Helpers
{
    public class CreateCategoryLists
    {
        public static Dictionary<string, ItemModule> CreatedCategoryList = new Dictionary<string, ItemModule>();


        //Get Total Pages from the packs and Loop into them to create a Category List With Packs information in the model CategoryPacksList
        public static async Task GetPacksList()
        {

            try
            {
                ShopPacksModule serverTotalPages = await GetPacksData.LoadPacks(GetLogedInServer._currentServerLoggedOn.serverID, "1");
                if (serverTotalPages != null)
                {
                    var cpage = Convert.ToInt16(serverTotalPages.currentPage);
                    var tpages = Convert.ToInt16(serverTotalPages.totalPages);

                    while (cpage <= tpages)
                    {
                        ShopPacksModule serverPacksList = await GetPacksData.LoadPacks(GetLogedInServer._currentServerLoggedOn.serverID, cpage.ToString());
                        if (serverPacksList != null)
                        {
                            foreach (var item in serverPacksList.packData)
                            {
                                if (item.categoryName == null)
                                {

                                }
                                else
                                {
                                    if (item.price == "0" || item.OverlayHidden || item.categoryName.Contains("welcome") || item.categoryName.Contains("war")
                                                                    || item.categoryName.Contains("daily") || item.categoryName.Contains("lottery")
                                                                    || item.categoryName.Contains("quests") || item.categoryName.Contains("wz")
                                                                    || item.categoryName.Contains("coins") || item.categoryName.Contains("special")
                                                                    || item.categoryName.Contains("admin") || item.categoryName.Contains("hidden"))
                                    {
                                    }
                                    else
                                    {
                                        var dictpacks = new ItemModule();
                                        dictpacks.price = item.price;
                                        dictpacks.name = item.name;
                                        dictpacks.packID = item.packID;
                                        dictpacks.description = item.description;
                                        dictpacks.imageURL = item.imageURL;
                                        dictpacks.categoryName = item.categoryName;
                                        CreatedCategoryList.Add(item.name, dictpacks);
                                    }
                                }

                            }
                            cpage++;
                        }

                    }
                }

                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + ex.StackTrace);

                return;
            }
        }
    }
}
