

////////////////////////////////////////////////////////////////////////
// Performance snippet
////////////////////////////////////////////////////////////////////////
CFTimeInterval start = CACurrentMediaTime();

// DO STUFF

CFTimeInterval end = CACurrentMediaTime();
NSLog(@"Took:%f",(end - start));


////////////////////////////////////////////////////////////////////////
// Promote an ability
////////////////////////////////////////////////////////////////////////
AbilityLevel* abilityLevel2  = [[GameFactory sharedUserManager].userPlayer.abilities getAbility:ABILITY_TODO_SB_2];
[abilityLevel2 addExp:100];
[abilityLevel2 promote];
[abilityLevel2 promote];
[abilityLevel2 promote];


////////////////////////////////////////////////////////////////////////
// Show specific event
////////////////////////////////////////////////////////////////////////
Class<EventProtocol> eventClass = (Class<EventProtocol>)NSClassFromString(@"GameEventIntro");
[self vcShow:[GameViewFactory eventView:[eventClass buildEvent:nil]]];


////////////////////////////////////////////////////////////////////////
// Ttoal Exp & Money given for all relationship rewards
////////////////////////////////////////////////////////////////////////
int expTotal = 0;
int moneyTotal = 0;
for (int indx = 0; indx < [[GameFactory sharedUserManager].userRelationships getHappinessRewardTotal]; indx++) {
    expTotal   += [[GameFactory sharedUserManager].userRelationships getHappinessExpRewardForLevel:indx];
    moneyTotal += [[GameFactory sharedUserManager].userRelationships getHappinessMoneyRewardForLevel:indx];
}

NSLog(@"Exp[%@]  money[%@]", [Helper commasToLongLongNumber:expTotal], [Helper commasToLongLongNumber:moneyTotal]);


////////////////////////////////////////////////////////////////////////
// Add Happiness and update Relationship VC
////////////////////////////////////////////////////////////////////////
[[GameFactory sharedUserManager].userRelationships addHappiness:2000];
[[GameFactory sharedUserManager].userRelationships weeklyProcessing];
[self refreshHappiness:NO];
[_tblReward reloadData];

////////////////////////////////////////////////////////////////////////
// get all teams in game
////////////////////////////////////////////////////////////////////////
NSMutableArray* allTeams = [[NSMutableArray alloc] init];
for (Conference* c in [[GameFactory sharedUserManager].gameData getAllConferences]) {
    [allTeams addObjectsFromArray:c.getTeams];
}

////////////////////////////////////////////////////////////////////////
// get all star teams for leaue and show
////////////////////////////////////////////////////////////////////////
League* nba = [[[GameFactory sharedUserManager].gameData getRegionForCountryCode:REGION_USA_COUNTRY_CODE] getLeagueByType:leagueType];

SBPair* allStar = [nba pickAllStarTeams];
[nba setAllStarEast:allStar.left west:allStar.right];
    
NSArray<Team*>* allStarTeams = [nba getAllStarTeams];
Team* east = [allStarTeams objectAtIndex:0];
Team* west = [allStarTeams objectAtIndex:1];

NSString* eastImg = [[nba.conferences objectAtIndex:0] getLogoPath];
NSString* westImg = [[nba.conferences objectAtIndex:1] getLogoPath];

[self vcShow:[GameViewFactory allStarView:nba.name
                                   t1Name:east.name t1LogoPath:eastImg t1Players:east.getPlayers t1Coach:east.getCoach
                                   t2Name:west.name t2LogoPath:westImg t2Players:west.getPlayers t2Coach:west.getCoach]];


////////////////////////////////////////////////////////////////////////
// 1v1
////////////////////////////////////////////////////////////////////////
Region* r   = [[GameFactory sharedUserManager].gameData getRegionForCountryCode:REGION_USA_COUNTRY_CODE];
League* l   = [r getLeagueByType:LEAGUE_NBA];
Team* t1    = [[l getAllTeams] objectAtIndex:0];
Team* t2    = [[l getAllTeams] objectAtIndex:1];

FootyPlayer* p1 = [HelperMaths pickRandomFromArray:t1.getPlayers];
FootyPlayer* p2 = [HelperMaths pickRandomFromArray:t2.getPlayers];

UserAbilities* a1 = [UserAbilities generateUserAbilitiesForRole:p1.role reputation:p1.getReputation];
UserAbilities* a2 = [UserAbilities generateUserAbilitiesForRole:p2.role reputation:p2.getReputation];

NSArray<NSString*>* abilityKeys = [HelperMaths pickRandomFromArray:[UserAbilities listAllAbilityKeys:NO] :[HelperMaths randomInt:1 :6]];

[self displayPopup:[GameViewFactory oneVOnePopupView:@"Event Desc"
                    selectedAbilitiesLeft:abilityKeys selectedAbilitiesRight:abilityKeys
                               playerLeft:p1 playerRight:p2
                            abilitiesLeft:a1 abilitiesRight:a2
                             autoProgress:NO completeBlock:^(FootyPlayer * _Nonnull winner) {
    NSLog(@"Winner:%@", winner.getName);
}] animated:NO];


////////////////////////////////////////////////////////////////////////
// 1v1 - Free Throw
////////////////////////////////////////////////////////////////////////
Region* r   = [[GameFactory sharedUserManager].gameData getRegionForCountryCode:REGION_USA_COUNTRY_CODE];
League* l   = [r getLeagueByType:LEAGUE_NBA];
Team* t1    = [[l getAllTeams] objectAtIndex:0];
Team* t2    = [[l getAllTeams] objectAtIndex:1];

FootyPlayer* p1 = [HelperMaths pickRandomFromArray:t1.getPlayers];
FootyPlayer* p2 = [HelperMaths pickRandomFromArray:t2.getPlayers];

UserAbilities* a1 = [UserAbilities generateUserAbilitiesForRole:p1.role reputation:p1.getReputation];
UserAbilities* a2 = [UserAbilities generateUserAbilitiesForRole:p2.role reputation:p2.getReputation];

UserAbilities* ft = [[UserAbilities alloc] initOpponentPressure:134];

NSArray<NSString*>* abilityKeys = [HelperMaths pickRandomFromArray:[UserAbilities listAllAbilityKeys:NO] :[HelperMaths randomInt:1 :6]];

if ([HelperMaths randomBoolean]) {
    [self displayPopup:[GameViewFactory oneVOnePopupView:@"Event Desc"
                                   selectedAbilitiesLeft:@[ABILITY_1V1_PRESSURE] selectedAbilitiesRight:abilityKeys
                                              playerLeft:nil playerRight:p2
                                           abilitiesLeft:ft abilitiesRight:a2
                                            autoProgress:NO completeBlock:^(FootyPlayer * _Nonnull winner) {
        NSLog(@"Winner:%@", winner.getName);
    }] animated:NO];
} else {
    [self displayPopup:[GameViewFactory oneVOnePopupView:@"Event Desc"
                                   selectedAbilitiesLeft:abilityKeys selectedAbilitiesRight:@[ABILITY_1V1_PRESSURE]
                                              playerLeft:p1 playerRight:nil
                                           abilitiesLeft:a1 abilitiesRight:ft
                                            autoProgress:NO completeBlock:^(FootyPlayer * _Nonnull winner) {
        NSLog(@"Winner:%@", winner.getName);
    }] animated:NO];
}

////////////////////////////////////////////////////////////////////////
// PLay all fixtures in region - performance testing
////////////////////////////////////////////////////////////////////////
Region* r                                   = [[GameFactory sharedUserManager].gameData getRegionForCountryCode:REGION_USA_COUNTRY_CODE];
NSArray<FixtureEntry*>* batchFixtures       = [[GameFactory sharedUserManager].gameData getFixturesForRegion:r];
NSLog(@"Fixture Count:%d", (int)[batchFixtures count]);

CFTimeInterval start = CACurrentMediaTime();

NSMutableArray<MatchReport*>* matchReports  = [[MatchSimulator playFixtures:batchFixtures showingMatch:NO] mutableCopy];

CFTimeInterval end = CACurrentMediaTime();
NSLog(@"Took:%f",(end - start));

////////////////////////////////////////////////////////////////////////
// Auto Join team
////////////////////////////////////////////////////////////////////////
Team* t1                = [[GameFactory sharedUserManager].gameData findTeamInRegion:@"United States" :@"Miami Heat"];
ContractOffer* tc       = [[ContractOffer alloc] init:t1];
[tc agreeWage:1000];
[[GameFactory sharedUserManager].userPlayer joinTeam:tc];

////////////////////////////////////////////////////////////////////////
// Winner VC
////////////////////////////////////////////////////////////////////////
if ([[GameFactory sharedUserManager].userSeason getCurrentWeekOfYearNo] == 4) {
    Team* t1 = [[GameFactory sharedUserManager].gameData findTeamInRegion:@"United States" :@"Golden State Warriors"];
    Team* t2 = [[GameFactory sharedUserManager].gameData findTeamInRegion:@"United States" :@"Houston Cougars"];

    [self vcShow:[GameViewFactory winnerSummaryView:@[t1, t2]]];
}
