import click
import functools


def common_options(f):
    """Define options shared between subcommands to avoid code duplication"""
    options = [
        click.option(
            "--res",
            "-r",
            default=10000,
            help="Size of windows in which to compute coverage, in basepairs.",
            show_default=True,
        ),
        click.option(
            "--skip",
            "-s",
            default=1000,
            help="Stride between windows, in basepairs.",
            show_default=True,
        ),
        click.option(
            "--bins",
            "-B",
            default=None,
            help="Tab-separated file of three columns (chromosome, start, end) without header containing a custom binning to use. Overrides --res and --skip, optional.",
            show_default=False,
        ),
        click.option(
            "--name",
            "-n",
            default=None,
            help="Name of the sample (plot title). Base name of input file by default",
        ),
        click.option(
            "--blacklist",
            "-b",
            default=None,
            help="Exclude those chromosomes from the plot. List of comma-separated chromosome names.",
        ),
        click.option(
            "--whitelist",
            "-w",
            default=None,
            help="Only include those chromosomes in the plot. List of comma-separated chromosome names.",
        ),
        click.option(
            "--out",
            "-o",
            default=None,
            help="Output file where to write the plot. If not provided, the plot is shown interactively",
            type=click.Path(exists=False),
        ),
        click.option(
            "--max-depth",
            "-m",
            default=100000,
            help="Maximum read depth permitted. Position with higher coverage will set to this value",
            type=int,
        ),
        click.option(
            "--no-filter",
            "-N",
            help="Use all reads. By default, PCR duplicates and secondary alignments are excluded",
            is_flag=True,
        ),
    ]
    return functools.reduce(lambda x, opt: opt(x), options, f)