from typing import Union
from typing import List


def to_sql_list(
    python_list: Union[str, int, float, List[Union[str, int, float]]],
    force_string: bool = False,
) -> str:
    """
    Turn a Python list into a SQL list.

    Parameters
    ----------
    python_list : str, int, or List of floats, ints, or strings
        Python list to convert to a SQL list.

    force_string : bool, optional
        Determine whether to force SQL list to be a list of strings. By default
        is False, and will detect the type of the first element in the list.

    Returns
    -------
    sql_list : str
        Return string in the form of (a,b,c,d) for insertion into sql
        query.

    Example
    -------
    Find all customers with an id of 1, 4, or 5.

    >>> import sqltools
    >>> cust_ids = [1, 4, 5]
    >>> query = f'''
    ...     --sql
    ...     SELECT
    ...         *
    ...     FROM
    ...         customer
    ...     WHERE
    ...         id IN {sqltools.to_sql_list(cust_ids)}
    ... '''
    >>> sqltools.run_query(query)
    """
    # If a single element in inputted, turn into list
    if isinstance(python_list, str):
        python_list = [python_list]
    elif isinstance(python_list, int):
        python_list = [python_list]
    elif isinstance(python_list, float):
        python_list = [python_list]

    if isinstance(python_list[0], str) or force_string:
        quote = "'"
    else:
        quote = ""

    sql_list = "("
    for item in python_list:
        sql_list += f"{quote}{item}{quote}, "
    sql_list = sql_list.strip(", ")
    sql_list += ")"
    return sql_list