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

namespace Example.Helpers
{
    internal class CreateSquad
    {

        public static List<PlayerInfoModule> SquadMembersInfo = new List<PlayerInfoModule>();
        public static SquadsModel SquadInfo = new SquadsModel();

        public static async Task GetSquadmembers()
        {

            try
            {
                SquadMembersInfo.Clear();
                Dictionary<string, SquadsModel> SquadList = await APIGetSquads.GetSquadsList(GetLogedInServer._currentServerLoggedOn.serverID);

                if (SquadList == null)
                {

                    //throw new NullReferenceException("Can't load Squad Info List");
                }
                else
                {

                    SquadInfo = SquadList.FirstOrDefault(squad => squad.Value.SquadMember.ContainsKey(UserPCSettings.activeSteamID.ToString())).Value;

                    if (SquadInfo != null)
                    {
                        foreach (var squad in SquadInfo.SquadMember.Values)
                        {
                            PlayerInfoModule squadMember = new PlayerInfoModule();
                            squadMember = await GetSquadPlayerMember.LoadPlayerData(squad.SteamID, GetLogedInServer._currentServerLoggedOn.serverID);
                            SquadMembersInfo.Add(squadMember);

                            //foreach (var member in squad.SquadMember.Values)
                            //{
                            //    Console.WriteLine($"- SteamID: {member.SteamID}, Rank: {member.Rank}");
                            //}

                        }
                    }
                    else
                    {
                        //throw new NullReferenceException("Player is not member of a Squad.");
                    }
                }


            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Source + ex.Message + ex.Data + ex.StackTrace);
            }
        }
    }
}
