# This file was auto generated by Styx.
# Do not edit this file directly.

import typing
import pathlib
from styxdefs import *

METRIC_MERGE_METADATA = Metadata(
    id="fc657fa415442ff85ef1c87698be56c45aad5857.boutiques",
    name="metric-merge",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetricMergeUpToParameters = typing.TypedDict('MetricMergeUpToParameters', {
    "@type": typing.NotRequired[typing.Literal["up_to"]],
    "last_column": str,
    "opt_reverse": bool,
})
MetricMergeUpToParametersTagged = typing.TypedDict('MetricMergeUpToParametersTagged', {
    "@type": typing.Literal["up_to"],
    "last_column": str,
    "opt_reverse": bool,
})


MetricMergeColumnParameters = typing.TypedDict('MetricMergeColumnParameters', {
    "@type": typing.NotRequired[typing.Literal["column"]],
    "column": str,
    "up_to": typing.NotRequired[MetricMergeUpToParameters | None],
})
MetricMergeColumnParametersTagged = typing.TypedDict('MetricMergeColumnParametersTagged', {
    "@type": typing.Literal["column"],
    "column": str,
    "up_to": typing.NotRequired[MetricMergeUpToParameters | None],
})


MetricMergeMetricParameters = typing.TypedDict('MetricMergeMetricParameters', {
    "@type": typing.NotRequired[typing.Literal["metric"]],
    "metric_in": InputPathType,
    "column": typing.NotRequired[list[MetricMergeColumnParameters] | None],
})
MetricMergeMetricParametersTagged = typing.TypedDict('MetricMergeMetricParametersTagged', {
    "@type": typing.Literal["metric"],
    "metric_in": InputPathType,
    "column": typing.NotRequired[list[MetricMergeColumnParameters] | None],
})


MetricMergeParameters = typing.TypedDict('MetricMergeParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metric-merge"]],
    "metric_out": str,
    "metric": typing.NotRequired[list[MetricMergeMetricParameters] | None],
})
MetricMergeParametersTagged = typing.TypedDict('MetricMergeParametersTagged', {
    "@type": typing.Literal["workbench/metric-merge"],
    "metric_out": str,
    "metric": typing.NotRequired[list[MetricMergeMetricParameters] | None],
})


def metric_merge_up_to_params(
    last_column: str,
    opt_reverse: bool = False,
) -> MetricMergeUpToParametersTagged:
    """
    Build parameters.
    
    Args:
        last_column: the number or name of the last column to include.
        opt_reverse: use the range in reverse order.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "up_to",
        "last_column": last_column,
        "opt_reverse": opt_reverse,
    }
    return params


def metric_merge_up_to_cargs(
    params: MetricMergeUpToParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-up-to")
    cargs.append(params.get("last_column", None))
    if params.get("opt_reverse", False):
        cargs.append("-reverse")
    return cargs


def metric_merge_column_params(
    column: str,
    up_to: MetricMergeUpToParameters | None = None,
) -> MetricMergeColumnParametersTagged:
    """
    Build parameters.
    
    Args:
        column: the column number or name.
        up_to: use an inclusive range of columns.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "column",
        "column": column,
    }
    if up_to is not None:
        params["up_to"] = up_to
    return params


def metric_merge_column_cargs(
    params: MetricMergeColumnParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-column")
    cargs.append(params.get("column", None))
    if params.get("up_to", None) is not None:
        cargs.extend(metric_merge_up_to_cargs(params.get("up_to", None), execution))
    return cargs


def metric_merge_metric_params(
    metric_in: InputPathType,
    column: list[MetricMergeColumnParameters] | None = None,
) -> MetricMergeMetricParametersTagged:
    """
    Build parameters.
    
    Args:
        metric_in: a metric file to use columns from.
        column: select a single column to use.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "metric",
        "metric_in": metric_in,
    }
    if column is not None:
        params["column"] = column
    return params


def metric_merge_metric_cargs(
    params: MetricMergeMetricParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("-metric")
    cargs.append(execution.input_file(params.get("metric_in", None)))
    if params.get("column", None) is not None:
        cargs.extend([a for c in [metric_merge_column_cargs(s, execution) for s in params.get("column", None)] for a in c])
    return cargs


class MetricMergeOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricMergeParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    metric_out: OutputPathType
    """the output metric"""


def metric_merge_params(
    metric_out: str,
    metric: list[MetricMergeMetricParameters] | None = None,
) -> MetricMergeParametersTagged:
    """
    Build parameters.
    
    Args:
        metric_out: the output metric.
        metric: specify an input metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metric-merge",
        "metric_out": metric_out,
    }
    if metric is not None:
        params["metric"] = metric
    return params


def metric_merge_cargs(
    params: MetricMergeParameters,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.append("wb_command")
    cargs.append("-metric-merge")
    cargs.append(params.get("metric_out", None))
    if params.get("metric", None) is not None:
        cargs.extend([a for c in [metric_merge_metric_cargs(s, execution) for s in params.get("metric", None)] for a in c])
    return cargs


def metric_merge_outputs(
    params: MetricMergeParameters,
    execution: Execution,
) -> MetricMergeOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = MetricMergeOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric_out", None)),
    )
    return ret


def metric_merge_execute(
    params: MetricMergeParameters,
    runner: Runner | None = None,
) -> MetricMergeOutputs:
    """
    metric-merge
    
    Merge metric files into a new file.
    
    Takes one or more metric files and constructs a new metric file by
    concatenating columns from them. The input metric files must have the same
    number of vertices and same structure.
    
    Example: wb_command -metric-merge out.func.gii -metric first.func.gii
    -column 1 -metric second.func.gii
    
    This example would take the first column from first.func.gii, followed by
    all columns from second.func.gii, and write these columns to out.func.gii.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricMergeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_MERGE_METADATA)
    params = execution.params(params)
    cargs = metric_merge_cargs(params, execution)
    ret = metric_merge_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_merge(
    metric_out: str,
    metric: list[MetricMergeMetricParameters] | None = None,
    runner: Runner | None = None,
) -> MetricMergeOutputs:
    """
    metric-merge
    
    Merge metric files into a new file.
    
    Takes one or more metric files and constructs a new metric file by
    concatenating columns from them. The input metric files must have the same
    number of vertices and same structure.
    
    Example: wb_command -metric-merge out.func.gii -metric first.func.gii
    -column 1 -metric second.func.gii
    
    This example would take the first column from first.func.gii, followed by
    all columns from second.func.gii, and write these columns to out.func.gii.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        metric_out: the output metric.
        metric: specify an input metric.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricMergeOutputs`).
    """
    params = metric_merge_params(
        metric_out=metric_out,
        metric=metric,
    )
    return metric_merge_execute(params, runner)


__all__ = [
    "METRIC_MERGE_METADATA",
    "MetricMergeOutputs",
    "metric_merge",
    "metric_merge_column_params",
    "metric_merge_execute",
    "metric_merge_metric_params",
    "metric_merge_params",
    "metric_merge_up_to_params",
]
