from app.main.data_model.games.stratedge.se_round import SERound


class RoundRepository:

    def __init__(self, session):
        self.session = session

    def get_round_by_id(self, round_id):
        stratedge_round = self.session.query(SERound).filter(SERound.id == round_id).all()
        if len(stratedge_round) == 0:
            return None
        return stratedge_round[0]

    def get_rounds_by_game_session_id(self, game_session_id):
        stratedge_rounds = self.session.query(SERound).filter(SERound.game_session_id == game_session_id).all()
        if len(stratedge_rounds) == 0:
            return None
        return stratedge_rounds

    def get_other_rounds_with_same_status(self, game_session_id, round_id, status):
        stratedge_rounds = self.session.query(SERound).filter(SERound.game_session_id == game_session_id).\
            filter(SERound.id != round_id).filter(SERound.status == status).all()
        if len(stratedge_rounds) == 0:
            return None
        return stratedge_rounds