"""Internal utilities for walkingpandas."""

from typing import List, Union


def _escape_sql_string(s: str) -> str:
    """Escape a string for safe use inside SQL single-quoted literals."""
    return s.replace("'", "''")


def _format_id_list_sql(values: List[Union[int, str]]) -> str:
    """Format a list of IDs for a SQL IN clause.

    Integer values are rendered bare (``1, 2, 3``); string values are
    single-quoted with escaping.
    """
    if not values:
        return ""
    if all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in values):
        return ", ".join(str(int(v)) for v in values)
    return ", ".join(f"'{_escape_sql_string(str(v))}'" for v in values)
