from importlib import resources
import pandas as pd


def _load_from_resource(resource_name: str) -> pd.DataFrame:
    """Loads data from user-specified resource

    :params:
    resource_name: str
      Name of the resource file (with or without the .zip extension)

    :returns:
    pd.DataFrame
      Contents of the zipped CSV file as a pandas DataFrame
    """
    if not resource_name.endswith(".zip"):
        # resource should be a zipped CSV file
        resource_name += ".zip"

    abs_path = resources.files("jrpyml") / "data" / resource_name
    return pd.read_csv(abs_path)


def load_usarrests():
    return _load_from_resource("usarrests.zip")


def load_beauty():
    return _load_from_resource("beauty.zip")


def load_starbucks():
    return _load_from_resource("starbucks.zip")


def load_bond():
    return _load_from_resource("bond.zip")


def load_movies():
    return _load_from_resource("movies.zip")


def load_chopsticks():
    return _load_from_resource("chopsticks.zip")


def load_chopsticks_full():
    return _load_from_resource("chopsticks_full.zip")


def load_correlation_example():
    return _load_from_resource("correlation.zip")


def load_titanic():
    return _load_from_resource("titanic.zip")


def load_head_size():
    return _load_from_resource("head_size.zip")
