from typing import Union
from pathlib import Path
import csv


def _preprocess_csv(file_path: Union[str, Path], delimiter: str):
    """Validates a CSV file and returns the data as a list of lists"""

    if isinstance(file_path, str):
        file_path = Path(file_path)
    if not file_path.exists():
        raise ValueError("File not found")

    with open(file_path, "r", encoding="utf-8") as file:
        reader = csv.reader(file, delimiter=delimiter)
        csv_data = list(reader)
    if not csv_data:
        raise ValueError("File is empty")

    return csv_data