import click
import functools


def common_args(func):
    """
    Decorator to contain CLI args that will be common to both CLI and GUI: title and engine args.
    """

    @click.option(
        "--title",
        "-t",
        metavar="<text>",
        help="Title to display. If omitted will use file name.")
    @click.option(
        "--about",
        metavar="<URL>",
        help="URL providing more information about the dataset "
             "(hint: must be a fully specified absolute URL).")
    @click.option(
        "--embedding",
        "-e",
        default=[],
        multiple=True,
        show_default=False,
        metavar="<text>",
        help="Embedding name, eg, 'umap'. Repeat option for multiple embeddings. Defaults to all."
    )
    @click.option(
        "--obs-names",
        "-obs",
        default=None,
        metavar="<text>",
        help="Name of annotation field to use for observations. If not specified cellxgene will use the the obs index.")
    @click.option(
        "--var-names",
        "-var",
        default=None,
        metavar="<text>",
        help="Name of annotation to use for variables. If not specified cellxgene will use the the var index.")
    @click.option(
        "--max-category-items",
        default=1000,
        metavar="<integer>",
        show_default=True,
        help="Will not display categories with more distinct values than specified.",)
    @click.option(
        "--diffexp-lfc-cutoff",
        "-de",
        default=0.01,
        show_default=True,
        metavar="<float>",
        help="Minimum log fold change threshold for differential expression.",)
    @click.option(
        "--experimental-annotations",
        is_flag=True,
        default=False,
        show_default=True,
        help="Enable user annotation of data."
    )
    @click.option(
        "--experimental-annotations-file",
        default=None,
        show_default=True,
        multiple=False,
        metavar="<path>",
        help="CSV file to initialize editing of existing annotations; will be altered in-place. "
             "Incompatible with --annotations-output-dir.",)
    @click.option(
        "--experimental-annotations-output-dir",
        default=None,
        show_default=False,
        multiple=False,
        metavar="<directory path>",
        help="Directory of where to save output annotations; filename will be specified in the application. "
             "Incompatible with --annotations-input-file.",)
    @click.option(
        "--backed",
        "-b",
        is_flag=True,
        default=False,
        show_default=False,
        help="Load data in file-backed mode. This may save memory, but may result in slower overall performance.")
    @click.option(
        "--disable-diffexp",
        is_flag=True,
        default=False,
        show_default=False,
        help="Disable on-demand differential expression.")
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)

    return wrapper