from app.main.data_model.games.leadedge.le_external_report import LEExternalReport
from app.main.data_model.games.leadedge.le_round import LERound


class LEExternalReportRepository:

    def __init__(self, session):
        self.session = session

    def find_external_reports_by_round_id(self, game_session_id, round_id):
        return self.session.query(LEExternalReport).join(LERound).filter(
            LEExternalReport.le_round_id == LERound.id,
            LERound.game_session_id == game_session_id,
            LEExternalReport.le_round_id <= round_id
        ).all()

    def find_last_external_report(self, round_id, game_session_id):
        return self.session.query(LEExternalReport).join(LERound).filter(
            LEExternalReport.le_round_id == LERound.id,
            LERound.game_session_id == game_session_id,
            LEExternalReport.le_round_id <= round_id
        ).order_by(LEExternalReport.id.desc()).first()

