from datetime import date
from typing import List

from sqlmodel import select

from config.config_utils import get_managed_teams_config
from src.api.fixtures_client import FixturesClient
from src.db.db_manager import NotifierDBManager
from src.db.notif_sql_models import Fixture as DBFixture
from src.db.notif_sql_models import League as DBLeague
from src.db.notif_sql_models import Team as DBTeam
from src.entities import Championship, Team
from src.utils.fixtures_utils import convert_fixture_response_to_db

NOTIFIER_DB_MANAGER = NotifierDBManager()


def insert_league(fixture_league: Championship) -> DBLeague:
    league_statement = select(DBLeague).where(DBLeague.id == fixture_league.league_id)
    retrieved_league = NOTIFIER_DB_MANAGER.select_records(league_statement)

    if not len(retrieved_league):
        league = DBLeague(
            id=fixture_league.league_id,
            name=fixture_league.name,
            logo=fixture_league.logo,
            country=fixture_league.country,
        )
        NOTIFIER_DB_MANAGER.insert_record(league)
        retrieved_league = NOTIFIER_DB_MANAGER.select_records(league_statement)

    return retrieved_league


def insert_team(fixture_team: Team) -> DBTeam:
    team_statement = 