"""Fetch match stats for individual games."""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/match.ipynb.

# %% auto 0
__all__ = ['fetch_all_matches', 'fetch_matches_by_date', 'fetch_match_details', 'fetch_matches']

# %% ../nbs/match.ipynb 4
import pandas as pd

# %% ../nbs/match.ipynb 5
def fetch_all_matches():
    """Fetches all match information that exists: \n
    * match_id \n
    * home_team \n
    * away_team \n
    * date
    """

    try:
        print("Fetching all matches...")
        date_url = "https://raw.githubusercontent.com/seanyboi/rugbydata/main/data/v3/match/match_registry.parquet"
        matches = pd.read_parquet(date_url, engine="pyarrow").sort_values(
            by="date", ascending=True
        )
        return matches
    except Exception as e:
        print(
            f"No match information either because no matches took place or rugbypy does not have access to the match data - {e}. Please raise an issue if neither."
        )

# %% ../nbs/match.ipynb 7
def fetch_matches_by_date(date: str):
    """Fetches all match information on a particular date in the format YYYYMMDD that includes: \n
    * match_id \n
    * competition_id \n
    * home_team_id \n
    * home_team_name \n
    * away_team_id \n
    * away_team_name \n
    """

    try:
        print(f"Fetching matches on date: {date}...")
        date_url = f"https://raw.githubusercontent.com/seanyboi/rugbydata/main/data/v3/dates/{date}.parquet"
        matches = pd.read_parquet(date_url, engine="pyarrow")
        return matches
    except Exception as _:
        print(
            f"No match information for matches played on {date} either because no matches took place or rugbypy does not have access to the match data. Please raise en issue if neither."
        )

# %% ../nbs/match.ipynb 9
def fetch_match_details(match_id: str):
    """Fetches match data for a certain match_id"""
    print(f"Fetching match details for match_id: {match_id}...")
    try:
        match_url = f"https://raw.githubusercontent.com/seanyboi/rugbydata/main/data/v3/match/{match_id}.parquet"
        matches = pd.read_parquet(match_url, engine="pyarrow")
        return matches
    except Exception as _:
        print("Error fetching match data. Please raise an issue!")

# %% ../nbs/match.ipynb 11
def fetch_matches(date: str):
    print("Deprecated, please use the fetch_matches_by_date() function instead")
