public static TeamColor GetTeamColor(string teamId)
        {
            JArray    o1 = JArray.Parse(File.ReadAllText(@"wwwroot/lib/TeamColors.json"));
            JToken    thisTeamColorToken = o1.FirstOrDefault(r => r["id"].ToString() == teamId);
            TeamColor thisTeamColor      = JsonConvert.DeserializeObject <TeamColor>(thisTeamColorToken.ToString());

            return(thisTeamColor);
        }
        public static void GetMatchResultsById(string matchId, string gameMode)
        {
            CurrentTeams = new List <List <string> > {
            };
            string mode = "";

            switch (gameMode)
            {
            case "1":
                mode = "arena";
                break;

            case "3":
                mode = "custom";
                break;

            case "4":
                mode = "warzone";
                break;

            default:
                break;
            }
            RestClient  client  = new RestClient("https://www.haloapi.com/");
            RestRequest request = new RestRequest($"/stats/h5/{mode}/matches/{matchId}");

            request.AddHeader("Ocp-Apim-Subscription-Key", EnvironmentVariables.HaloApiKey);
            RestResponse response = new RestResponse();

            Task.Run(async() =>
            {
                response = await GetResponseContentAsync(client, request) as RestResponse;
            }).Wait();

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                CurrentMatchResults = JsonConvert.DeserializeObject <Root>(response.Content);
                var possibleTeams = new List <String>[8] {
                    new List <String> {
                    }, new List <String> {
                    }, new List <String> {
                    }, new List <String> {
                    }, new List <String> {
                    }, new List <String> {
                    }, new List <String> {
                    }, new List <String> {
                    }
                };
                for (int i = 0; i < CurrentMatchResults.PlayerStats.Count; i++)
                {
                    if (CurrentMatchResults.PlayerStats[i].DNF)
                    {
                        possibleTeams[CurrentMatchResults.PlayerStats[i].TeamId].Add(CurrentMatchResults.PlayerStats[i].Player.Gamertag + " -- DNF");
                    }
                    else
                    {
                        possibleTeams[CurrentMatchResults.PlayerStats[i].TeamId].Add(CurrentMatchResults.PlayerStats[i].Player.Gamertag);
                    }
                }
                for (int i = 0; i < possibleTeams.Length; i++)
                {
                    if (possibleTeams[i].Count > 0)
                    {
                        TeamColor color = TeamColor.GetTeamColor(i.ToString());
                        possibleTeams[i].Insert(0, color.name);
                        CurrentTeams.Add(possibleTeams[i]);
                    }
                }
            }
        }
        public static PlayerMatchHistory.Root GetPlayerMatchHistory(string gamertag, string modes)
        {
            RestClient  client  = new RestClient("https://www.haloapi.com/");
            RestRequest request = new RestRequest($"/stats/h5/players/{gamertag}/matches?&modes={modes}&count=8");

            request.AddHeader("Ocp-Apim-Subscription-Key", EnvironmentVariables.HaloApiKey);
            RestResponse response = new RestResponse();

            Task.Run(async() =>
            {
                response = await GetResponseContentAsync(client, request) as RestResponse;
            }).Wait();

            PlayerMatchHistory.Root returnedHistory = JsonConvert.DeserializeObject <PlayerMatchHistory.Root>(response.Content);
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                for (int i = 0; i < returnedHistory.Results.Count; i++)
                {
                    //Converts GameCompletedDate from ISO 8601 to readable string
                    string formattedTime = DateTime.ParseExact(returnedHistory.Results[i].MatchCompletedDate.ISO8601Date.Replace("T", " "), "u", CultureInfo.InvariantCulture).ToString();
                    returnedHistory.Results[i].MatchCompletedDate.ISO8601Date = formattedTime.Remove(formattedTime.Length - 12);

                    //Gets team name from Json
                    returnedHistory.Results[i].Players[0].TeamDisplay = TeamColor.GetTeamColor(returnedHistory.Results[i].Players[0].TeamId).name;

                    //Finds GameBaseVariant from Json
                    returnedHistory.Results[i].GameBaseVariant = GameBaseVariant.GetGameBaseVariant(returnedHistory.Results[i].GameBaseVariantId);
                    if (returnedHistory.Results[i].HopperId != null)
                    {
                        returnedHistory.Results[i].Playlist = Playlist.GetPlaylist(returnedHistory.Results[i].HopperId);
                    }
                    else
                    {
                        returnedHistory.Results[i].Playlist = new Playlist()
                        {
                            name = "Customs"
                        };
                    }
                    //Finds official mapvariants from API
                    if (returnedHistory.Results[i].MapVariant.OwnerType == "3")
                    {
                        RestRequest requestMap = new RestRequest($"/metadata/h5/metadata/map-variants/{returnedHistory.Results[i].MapVariant.ResourceId}");
                        requestMap.AddHeader("Ocp-Apim-Subscription-Key", EnvironmentVariables.HaloApiKey2);
                        RestResponse responseMap = new RestResponse();

                        Task.Run(async() =>
                        {
                            responseMap = await GetResponseContentAsync(client, requestMap) as RestResponse;
                        }).Wait();

                        JObject returnedMapJson = JObject.Parse(responseMap.Content);
                        string  returnedMap     = returnedMapJson["name"].ToString();
                        returnedHistory.Results[i].MapVariant.Name = returnedMap;
                    }
                    //Finds mapvariants for UGC from API
                    else if (returnedHistory.Results[i].MapVariant.OwnerType == "1")
                    {
                        RestRequest requestUgcMap = new RestRequest($"/ugc/h5/players/{returnedHistory.Results[i].MapVariant.Owner}/mapvariants/{returnedHistory.Results[i].MapVariant.ResourceId}");
                        requestUgcMap.AddHeader("Ocp-Apim-Subscription-Key", EnvironmentVariables.HaloApiKey2);
                        RestResponse responseUgcMap = new RestResponse();

                        Task.Run(async() =>
                        {
                            responseUgcMap = await GetResponseContentAsync(client, requestUgcMap) as RestResponse;
                        }).Wait();

                        if (responseUgcMap.StatusCode == System.Net.HttpStatusCode.OK)
                        {
                            JObject returnedMapJson = JObject.Parse(responseUgcMap.Content);
                            string  returnedMap     = returnedMapJson["Name"].ToString();
                            returnedHistory.Results[i].MapVariant.Name = returnedMap;
                        }
                        else
                        {
                            returnedHistory.Results[i].MapVariant.Name = "Unknown Map";
                        }
                    }
                    else
                    {
                        returnedHistory.Results[i].MapVariant.Name = "Unknown Map";
                    }
                }
            }
            return(returnedHistory);
        }