//  Run once only
        //  Run on 17/12/2018

        /*public async Task AddDivisionsAsync()
         * {
         *
         *  var dataSources = new List<Division>()
         *  {
         *      new Division()
         *      {
         *
         *          DivisionName = "NL First Division 18/19",
         *          DivisionCode = "DIV1",
         *      },
         *      new Division()
         *      {
         *          DivisionName = "NL Second Division 18/19",
         *          DivisionCode = "DIV2"
         *      },
         *      new Division()
         *      {
         *          DivisionName = "NL Third Division 18/19",
         *          DivisionCode = "DIV3",
         *      }
         *  };
         *
         *  foreach (var item in dataSources)
         *  {
         *      await _wpbService.CreateDivisionAsync(item);
         *  }
         * }
         *
         * /// <summary>
         * /// Only need to run this function once
         * /// RUN COMPLETE
         * /// </summary>
         * /// <returns></returns>
         * public async Task GetFixturesDataAsync()
         * {
         *  //  Get all the fixtures dataSources
         *  var fixturesDataSource = await _wpbService.GetFixtureDataSources();
         *
         *  foreach (var src in fixturesDataSource)
         *  {
         *      var fixturesResults =
         *          ParseDataSource.ParseFixturesDataSource(src, src.ClassNameNode);
         *
         *      foreach (var ftr in fixturesResults)
         *      {
         *          try
         *          {
         *              //  get Home team details
         *              var teamHome = await _wpbService.GetTeamByTeamName(ftr.FixtureHomeTeamName);
         *              var teamAway = await _wpbService.GetTeamByTeamName(ftr.FixtureAwayTeamName);
         *
         *              if (teamHome != null && teamAway != null)
         *              {
         *                  var newFixture = new Fixture()
         *                  {
         *                      FixtureDate = ftr.FixtureDate,
         *                      HomeTeamId = teamHome.Id,
         *                      HomeTeamName = teamHome.TeamName,
         *                      HomeTeamCode = teamHome.TeamCode,
         *                      AwayTeamId = teamAway.Id,
         *                      AwayTeamName = teamAway.TeamName,
         *                      AwayTeamCode = teamAway.TeamCode,
         *                      //  already have the subdivision in both Home or Away team
         *                      SubDivisionId = teamHome.SubDivisionId
         *                  };
         *
         *                  //  Check for null values!!
         *                  await _wpbService.CreateFixtureAsync(newFixture);
         *              }
         *              else
         *              {
         *                  throw new System.ArgumentException(
         *                      "Detected null values in either teamHome, teamAway or subDivision variable!");
         *              }
         *          }
         *          catch (Exception err)
         *          {
         *              var msg = err.ToString();
         *          }
         *      }
         *  }
         *
         * }
         */

        public async Task GetMatchResultsAsync()
        {
            //  Get all the data sources for results
            var resultsDataSource = await _wpbService.GetAllResultDataSourceAsync();

            foreach (var result in resultsDataSource)
            {
                var matchResults =
                    ParseDataSource.ParseResultDataSource(result, result.ClassNameNode);

                foreach (var game in matchResults)
                {
                    try
                    {
                        var teamHome = await _wpbService.GetTeamByTeamName(game.HomeTeamName);

                        var teamAway = await _wpbService.GetTeamByTeamName(game.AwayTeamName);

                        if (teamHome != null && teamAway != null)
                        {
                            var winningTeam   = (game.WinningTeamName == teamHome.TeamName) ? teamHome : teamAway;
                            var encodedResult = EncodeGameResult(teamHome.TeamName, teamAway.TeamName, result.TimeStamp);

                            var newResult = new GameResult()
                            {
                                TimeStamp       = game.TimeStamp,
                                HomeTeamId      = teamHome.Id,
                                HomeTeamName    = teamHome.TeamName,
                                HomeTeamCode    = teamHome.TeamCode,
                                AwayTeamId      = teamAway.Id,
                                AwayTeamName    = teamAway.TeamName,
                                AwayTeamCode    = teamAway.TeamCode,
                                Score           = game.Score,
                                WinningTeamName = winningTeam.TeamName,
                                WinningTeamCode = winningTeam.TeamCode,
                                //  already have the subdivision in both Home or Away team
                                SubDivisionId = teamHome.SubDivisionId,
                                EncodedResult = encodedResult
                            };

                            var resultExist = await _wpbService.GameResultExistAsync(newResult.EncodedResult);

                            //  only add if not in db
                            if (resultExist == false)
                            {
                                await _wpbService.CreateGameResultAsync(newResult);
                            }
                        }
                        else
                        {
                            throw new System.ArgumentException(
                                      "Detected null values in either teamHome, teamAway or subDivision variable!");
                        }
                    }
                    catch (Exception err)
                    {
                        var msg = err.ToString();
                    }
                }
            }

            //  add new report tracker object
            var newReportRun = new ReportTracker()
            {
                ReportTypeCode = ModelHelpers.REPORT_RSLT
            };
            await _wpbService.CreateReportHistory(newReportRun);
        }