import re
import click


def parse_table_name(table_name: str) -> str:
    """Check if ``table_name`` is a valid name for a PostgreSQL table.

    Parameters
    ----------
    table_name : str
        Possible table name.

    Returns
    -------
    table_name : str
        Valid table name

    Raises
    ------
    click.BadParameter
        If ``table_name`` is not valid for PSQL.

    """
    if re.fullmatch(r'^[a-z][a-z_]{5,}', table_name):
        return table_name
    else:
        raise click.BadParameter(
            'ERROR: Use only lower-case characters and underscores.')