from app.main.data_model.games.stratedge.se_player import SEPlayer
from app.main.data_model.games.stratedge.se_team import SETeam


class PlayerRepository:

    def __init__(self, session):
        self.session = session

    def get_player_by_participant_id_and_game_session_id(self, participant_id, game_session_id):
        player = self.session.query(SEPlayer).join(SETeam).\
            filter(SEPlayer.team_id == SETeam.id).\
            filter(SEPlayer.player_user_id == participant_id).\
            filter(SETeam.game_session_id == game_session_id).all()
        if len(player) == 0:
            return None
        return player[0]

    def get_players_by_game_session_id(self, game_session_id):
        players = self.session.query(SEPlayer).join(SETeam).\
            filter(SEPlayer.team_id == SETeam.id). \
            filter(SETeam.game_session_id == game_session_id).all()
        if len(players) == 0:
            return None
        return players
