"""Tests for the combined team model class."""
import datetime
import os
import unittest

import requests_mock
import requests_cache
from sportsball.data.combined.combined_team_model import create_combined_team_model
from sportsball.data.team_model import TeamModel
from sportsball.data.player_model import PlayerModel
from sportsball.data.species import Species


class TestCombinedTeamModel(unittest.TestCase):

    def setUp(self):
        self._session = requests_cache.CachedSession(backend="memory")
        self.dir = os.path.dirname(__file__)

    def test_names_resolve(self):
        with requests_mock.Mocker() as m:
            names = {}
            coach_names = {}
            player_models = [PlayerModel(
                identifier="1",
                jersey=None,
                kicks=None,
                fumbles=None,
                fumbles_lost=None,
                field_goals=None,
                field_goals_attempted=None,
                offensive_rebounds=None,
                assists=None,
                turnovers=None,
                name="Johnny Johnson",
                marks=None,
                handballs=None,
                disposals=None,
                goals=None,
                behinds=None,
                hit_outs=None,
                tackles=None,
                rebounds=None,
                insides=None,
                clearances=None,
                clangers=None,
                free_kicks_for=None,
                free_kicks_against=None,
                brownlow_votes=None,
                contested_possessions=None,
                uncontested_possessions=None,
                contested_marks=None,
                marks_inside=None,
                one_percenters=None,
                bounces=None,
                goal_assists=None,
                percentage_played=None,
                birth_date=None,
                age=None,
                species=str(Species.HUMAN),
                handicap_weight=None,
                father=None,
                starting_position=None,
                weight=None,
                birth_address=None,
                owner=None,
            )]
            team_models = [TeamModel(
                identifier="a",
                name="Team A",
                location=None,
                players=player_models,
                odds=[],
                points=None,
                ladder_rank=None,
                news=[],
                social=[],
                coaches=[],
                lbw=None,
                end_dt=None,
            )]
            team_model = create_combined_team_model(
                team_models=team_models,
                identifier="a",
                player_identity_map={},
                names=names,
                coach_names=coach_names,
            )
            player_models_2 = [PlayerModel(
                identifier="1a",
                jersey=None,
                kicks=None,
                fumbles=None,
                fumbles_lost=None,
                field_goals=None,
                field_goals_attempted=None,
                offensive_rebounds=None,
                assists=None,
                turnovers=None,
                name="Johnny Johnson",
                marks=None,
                handballs=None,
                disposals=None,
                goals=None,
                behinds=None,
                hit_outs=None,
                tackles=None,
                rebounds=None,
                insides=None,
                clearances=None,
                clangers=None,
                free_kicks_for=None,
                free_kicks_against=None,
                brownlow_votes=None,
                contested_possessions=None,
                uncontested_possessions=None,
                contested_marks=None,
                marks_inside=None,
                one_percenters=None,
                bounces=None,
                goal_assists=None,
                percentage_played=None,
                birth_date=None,
                age=None,
                species=str(Species.HUMAN),
                handicap_weight=None,
                father=None,
                starting_position=None,
                weight=None,
                birth_address=None,
                owner=None,
            )]
            team_models_2 = [TeamModel(
                identifier="a",
                name="Team A",
                location=None,
                players=player_models_2,
                odds=[],
                points=None,
                ladder_rank=None,
                news=[],
                social=[],
                coaches=[],
                lbw=None,
                end_dt=None,
            )]
            team_model_2 = create_combined_team_model(
                team_models=team_models_2,
                identifier="a",
                player_identity_map={},
                names=names,
                coach_names=coach_names,
            )
            self.assertEqual(team_model.players[0].identifier, team_model_2.players[0].identifier)

    def test_names_resolve_with_surname_firstname(self):
        with requests_mock.Mocker() as m:
            names = {}
            coach_names = {}
            player_models = [PlayerModel(
                identifier="1",
                jersey=None,
                kicks=None,
                fumbles=None,
                fumbles_lost=None,
                field_goals=None,
                field_goals_attempted=None,
                offensive_rebounds=None,
                assists=None,
                turnovers=None,
                name="Johnny Johnson",
                marks=None,
                handballs=None,
                disposals=None,
                goals=None,
                behinds=None,
                hit_outs=None,
                tackles=None,
                rebounds=None,
                insides=None,
                clearances=None,
                clangers=None,
                free_kicks_for=None,
                free_kicks_against=None,
                brownlow_votes=None,
                contested_possessions=None,
                uncontested_possessions=None,
                contested_marks=None,
                marks_inside=None,
                one_percenters=None,
                bounces=None,
                goal_assists=None,
                percentage_played=None,
                birth_date=None,
                age=None,
                species=str(Species.HUMAN),
                handicap_weight=None,
                father=None,
                starting_position=None,
                weight=None,
                birth_address=None,
                owner=None,
            )]
            team_models = [TeamModel(
                identifier="a",
                name="Team A",
                location=None,
                players=player_models,
                odds=[],
                points=None,
                ladder_rank=None,
                news=[],
                social=[],
                coaches=[],
                lbw=None,
                end_dt=None,
            )]
            team_model = create_combined_team_model(
                team_models=team_models,
                identifier="a",
                player_identity_map={},
                names=names,
                coach_names=coach_names,
            )
            player_models_2 = [PlayerModel(
                identifier="1a",
                jersey=None,
                kicks=None,
                fumbles=None,
                fumbles_lost=None,
                field_goals=None,
                field_goals_attempted=None,
                offensive_rebounds=None,
                assists=None,
                turnovers=None,
                name="Johnson, Johnny",
                marks=None,
                handballs=None,
                disposals=None,
                goals=None,
                behinds=None,
                hit_outs=None,
                tackles=None,
                rebounds=None,
                insides=None,
                clearances=None,
                clangers=None,
                free_kicks_for=None,
                free_kicks_against=None,
                brownlow_votes=None,
                contested_possessions=None,
                uncontested_possessions=None,
                contested_marks=None,
                marks_inside=None,
                one_percenters=None,
                bounces=None,
                goal_assists=None,
                percentage_played=None,
                birth_date=None,
                age=None,
                species=str(Species.HUMAN),
                handicap_weight=None,
                father=None,
                starting_position=None,
                weight=None,
                birth_address=None,
                owner=None,
            )]
            team_models_2 = [TeamModel(
                identifier="a",
                name="Team A",
                location=None,
                players=player_models_2,
                odds=[],
                points=None,
                ladder_rank=None,
                news=[],
                social=[],
                coaches=[],
                lbw=None,
                end_dt=None,
            )]
            team_model_2 = create_combined_team_model(
                team_models=team_models_2,
                identifier="a",
                player_identity_map={},
                names=names,
                coach_names=coach_names,
            )
            self.assertEqual(team_model.players[0].identifier, team_model_2.players[0].identifier)
