from src.models.odds import Odds
from src.repositories.odds_repository import OddsRepository
from src.services.fixture_service import FixtureService


class OddsService:
    def __init__(self, db_name):
        self.odds_repository = OddsRepository(db_name)
        self.fixture_service = FixtureService()

    def upsert_many_odds(self, odds):
        self.odds_repository.upsert_many_odds(odds)

    def insert_odds(self, odds):
        self.odds_repository.insert_odds(odds)

    def get_team_odds(self, team_id: str, league_id: str, season: str):
        fixture_ids = self.fixture_service.get_fixture_ids(team_id, league_id, season)
        team_odds = self.odds_repository.get_team_odds(fixture_ids)
        team_odds = [Odds.from_dict(response['data']) for response in team_odds]

        return team_odds

    def get_league_odds(self, league_id: str, season: str):
        league_odds = self.odds_repository.get_league_odds(league_id, season)
        league_odds = [Odds.from_dict(response['data']) for response in league_odds]

        return league_odds
