"""
Data loader module for the bouncing ball analysis project.
"""

import pandas as pd
import os

# File paths for golf ball data
GOLF_BALL_PATHS = {
    "11 inches": "src/data/golf/golf_11.csv",
    "12 inches": "src/data/golf/golf_12.csv",
    "13 inches": "src/data/golf/golf_13.csv",
    "14 inches": "src/data/golf/golf_14.csv",
    "15 inches": "src/data/golf/golf_15.csv"
}

# File paths for lacrosse ball data
LACROSSE_BALL_PATHS = {
    "18 inches": "src/data/lacrosse/l_18.csv",
    "19 inches": "src/data/lacrosse/l_19.csv",
    "20 inches": "src/data/lacrosse/l_20.csv",
    "21 inches": "src/data/lacrosse/l_21.csv",
    "22 inches": "src/data/lacrosse/l_22.csv"
}

# File paths for metal ball data
METAL_BALL_PATHS = {
    "2 inches":  "src/data/metal/metal_2.csv",
    "4 inches":  "src/data/metal/metal_4.csv",
    "6 inches":  "src/data/metal/metal_6.csv",
    "8 inches":  "src/data/metal/metal_8.csv",
    "10 inches": "src/data/metal/metal_10.csv"
}

def read_trial(path):
    """
    Reads a CSV file containing time and position data (with no header)
    and returns a DataFrame with columns 'Time' and 'Position'.
    
    Parameters:
        path (str): Path to the CSV file
        
    Returns:
        pandas.DataFrame: DataFrame with 'Time' and 'Position' columns
    """
    return pd.read_csv(path, header=None, names=['Time', 'Position'])

def get_data_path(file_name):
    """
    Get the absolute path to a data file.
    
    Parameters:
        file_name (str): Name of the data file
        
    Returns:
        str: Absolute path to the data file
    """
    # Check if the file exists as provided
    if os.path.exists(file_name):
        return file_name
    
    # Check if the file exists in the data directory
    data_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'data')
    data_path = os.path.join(data_dir, file_name)
    if os.path.exists(data_path):
        return data_path
    
    # If not found, return the original path and let the caller handle the error
    return file_name

def load_trial(file_name):
    """
    Load a trial from a CSV file.
    
    Parameters:
        file_name (str): Name of the CSV file
        
    Returns:
        pandas.DataFrame: DataFrame with 'Time' and 'Position' columns
    """
    # The file_name is now a full path, so we can use it directly
    return read_trial(file_name) 