import json
import os
import sys
from datetime import datetime

sys.path.append(os.path.dirname(os.path.dirname(__file__)))

from src.lolpedia_api import (
    AuthCredentials,
    LeaguepediaClient,
    and_,
    desc,
    or_,
    select,
    tables,
)


def prettyprint(data):
    """Horrible function but we're hear for test and fast iteration."""

    try:
        print(json.dumps(data, indent=4))
    except Exception:
        print(data)


creds = AuthCredentials(user_file="bot")
client = LeaguepediaClient(creds)

P = tables.Player
PR = tables.PlayerRedirect
SP = tables.ScoreboardPlayer
SG = tables.ScoreboardGame
ST = tables.ScoreboardTeam


statement = (
    select(P.Name, ST.Bans, ST.StatsPage)
    .select_from(P)
    .join(PR, P.OverviewPage == PR.OverviewPage)
    .join(SP, PR.AllName == SP.Link)
    .join(SG, SP.GameId == SG.GameId)
    .join(ST, SP.GameId == ST.GameId)
    .where(
        and_(
            PR.AllName == "Caliste",
            SP.Kills > 5,
            SP.DateTime_UTC >= datetime(2026, 1, 1),
        )
    )
    .limit(1)
)

prettyprint(client.execute_query(statement))

######

statement = (
    select(PR.AllName)
    .select_from(SG)
    .join(SP, SG.GameId == SP.GameId)
    .join(PR, SP.Link == PR.AllName)
    .where(
        and_(
            PR.AllName == "Caliste",
            SP.Kills > 5,
            SP.DateTime_UTC >= datetime(2026, 1, 1),
        )
    )
    .limit(1)
)

prettyprint(client.execute_query(statement))
