import requests

from nba_data.data.current_season_only import CurrentSeasonOnly
from nba_data.data.date_range import DateRange
from nba_data.data.league import League
from nba_data.data.season import Season
from nba_data.data.season_type import SeasonType
from nba_data.deserializers.advanced_box_score_deserializer import AdvancedBoxScoreDeserializer
from nba_data.deserializers.calendar import CalendarDeserializer
from nba_data.deserializers.common_all_players_deserializer import CommonAllPlayersDeserializer
from nba_data.deserializers.common_player_info_deserializer import CommonPlayerInfoDeserializer
from nba_data.deserializers.season_players import SeasonPlayersDeserializer
from nba_data.deserializers.scoreboard import ScoreboardDeserializer
from nba_data.deserializers.team_game_log_deserializer import TeamGameLogDeserializer
from nba_data.deserializers.traditional_box_score_deserializer import TraditionalBoxScoreDeserializer
from nba_data.nba_stats_api_utils.query_parameter_generator import QueryParameterGenerator
from nba_data.nba_stats_api_utils.uri_generator import UriGenerator


class Client:

    headers = {'user-agent': ('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) '
                              'AppleWebKit/537.36 (KHTML, like Gecko) '
                              'Chrome/45.0.2454.101 Safari/537.36'),
               'referer': 'http://stats.nba.com/scores/'}

    def __init__(self):
        pass

    @staticmethod
    def get_all_nba_players():
        return Client.get_players_for_season(season=Season.season_2015, current_season_only=CurrentSeasonOnly.no)

    @staticmethod
    def get_players_for_season(season, league=League.nba, current_season_only=CurrentSeasonOnly.yes):
        response = requests.get(UriGenerator.generate_common_all_players_uri(),
                                headers=Client.headers,
                                params=QueryParameterGenerator.generate_request_parameters(season=season,
                                                                                           league=league,
                                                                                           current_season_only=current_season_only))

        response.raise_for_status()

        return CommonAllPlayersDeserializer.deserialize(response.json())

    @staticmethod
    def get_games_for_team(season, team, season_type=SeasonType.regular_season):
        response = requests.get(UriGenerator.generate_team_game_log_uri(),
                                headers=Client.headers,
                                params=QueryParameterGenerator.generate_request_parameters(season=season,
                                                                                           season_type=season_type,
                                                                                           team=team))
        response.raise_for_status()

        return TeamGameLogDeserializer.deserialize(response.json())

    @staticmethod
    def get_player_info(player_id):
        response = requests.get(UriGenerator.generate_common_player_info_uri(),
                                headers=Client.headers,
                                params=QueryParameterGenerator.generate_request_parameters(player_id=player_id))
        response.raise_for_status()

        return CommonPlayerInfoDeserializer.deserialize(response.json())

    @staticmethod
    def get_advanced_box_score(game_id):
        response = requests.get(UriGenerator.generate_advanced_box_score_uri(),
                                headers=Client.headers,
                                params=QueryParameterGenerator.generate_box_score_request_parameters(game_id=game_id))

        response.raise_for_status()

        return AdvancedBoxScoreDeserializer().deserialize(data=response.json())

    @staticmethod
    def get_traditional_box_score(game_id):
        response = requests.get(UriGenerator.generate_traditional_box_score_uri(),
                                headers=Client.headers,
                                params=QueryParameterGenerator.generate_box_score_request_parameters(game_id=game_id))

        response.raise_for_status()

        return TraditionalBoxScoreDeserializer().deserialize(data=response.json())

    @staticmethod
    def get_game_counts_in_date_range(date_range=DateRange(), ignore_dates_without_games=True):
        response = requests.get(UriGenerator.generate_calendar_data_uri(),
                                headers=Client.headers)

        response.raise_for_status()

        return CalendarDeserializer.deserialize(calendar_json=response.json(), date_range=date_range,
                                                ignore_dates_without_games=ignore_dates_without_games)

    @staticmethod
    def get_games_for_date(date_value):
        response = requests.get(UriGenerator.generate_scoreboard_data_uri(date_value=date_value),
                                headers=Client.headers)

        response.raise_for_status()

        return ScoreboardDeserializer.deserialize(data=response.json())

    @staticmethod
    def get_players(season):
        response = requests.get(UriGenerator.generate_players_data_uri(season=season),
                                headers=Client.headers)

        response.raise_for_status()

        return SeasonPlayersDeserializer.deserialize(data=response.json())

@@ -1431,16 +1431,251 @@
   pass%0A%0A
+    @staticmethod%0A    def make_request(uri, parameters, deserializer):%0A        response = requests.get(uri, headers=Client.headers, params=parameters)%0A%0A        response.raise_for_status()%0A%0A        return deserializer(response.json())%0A%0A
     @sta
@@ -2652,38 +2652,45 @@
       re
-sponse = 
+turn Client.make_
 request
-s.get(
+(uri=
 UriGener
@@ -2731,61 +2731,8 @@
 %0A   
-                             headers=Client.headers,%0A
     
@@ -2756,32 +2756,36 @@
            param
+eter
 s=QueryParameter
@@ -2928,16 +2928,23 @@
         
+   
+    
 season_t
@@ -3051,16 +3051,23 @@
         
+       
 team=tea
@@ -3068,17 +3068,17 @@
 am=team)
-)
+,
 %0A       
@@ -3082,52 +3082,48 @@
     
-response.raise_for_status()%0A%0A        return 
+                           deserializer=
 Team
@@ -3153,32 +3153,16 @@
 erialize
-(response.json()
 )%0A%0A    @

implement generic client request method