import click


def validate_dbname(ctx, params, value):
    """Validate a database name."""
    # pylint: disable=W0613
    # Check for forbidden characters
    forbidden_chars = ["/", "<", ">", ":", "\"", "\\", "|", "?", "*"]
    if any([c in value for c in forbidden_chars]):
        raise click.BadParameter("Invalid file name.")

    # Check for multiple extensions
    if len(value.split(".")) > 2:
        raise click.BadParameter("Invalid file name.")

    # Check for no extension
    try:
        _, ext = value.split(".")
    except ValueError:
        ext = "sql"
        value += "." + ext

    # Check for wrong extension
    if ext not in ["sql", "sqlite3", "sqlite", "sqlite2", "db"]:
        raise click.BadParameter("Invalid file name extension")

    return value