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

import typing
import pathlib
from styxdefs import *

METRIC_MASK_METADATA = Metadata(
    id="63170647bafcd7131594caf978d3951bd09b8dc0.boutiques",
    name="metric-mask",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetricMaskParameters = typing.TypedDict('MetricMaskParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metric-mask"]],
    "metric": InputPathType,
    "mask": InputPathType,
    "metric_out": str,
    "opt_column_column": typing.NotRequired[str | None],
})
MetricMaskParametersTagged = typing.TypedDict('MetricMaskParametersTagged', {
    "@type": typing.Literal["workbench/metric-mask"],
    "metric": InputPathType,
    "mask": InputPathType,
    "metric_out": str,
    "opt_column_column": typing.NotRequired[str | None],
})


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


def metric_mask_params(
    metric: InputPathType,
    mask: InputPathType,
    metric_out: str,
    opt_column_column: str | None = None,
) -> MetricMaskParametersTagged:
    """
    Build parameters.
    
    Args:
        metric: the input metric.
        mask: the mask metric.
        metric_out: the output metric.
        opt_column_column: select a single column: the column number or name.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metric-mask",
        "metric": metric,
        "mask": mask,
        "metric_out": metric_out,
    }
    if opt_column_column is not None:
        params["opt_column_column"] = opt_column_column
    return params


def metric_mask_cargs(
    params: MetricMaskParameters,
    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-mask")
    cargs.append(execution.input_file(params.get("metric", None)))
    cargs.append(execution.input_file(params.get("mask", None)))
    cargs.append(params.get("metric_out", None))
    if params.get("opt_column_column", None) is not None:
        cargs.extend([
            "-column",
            params.get("opt_column_column", None)
        ])
    return cargs


def metric_mask_outputs(
    params: MetricMaskParameters,
    execution: Execution,
) -> MetricMaskOutputs:
    """
    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 = MetricMaskOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric_out", None)),
    )
    return ret


def metric_mask_execute(
    params: MetricMaskParameters,
    runner: Runner | None = None,
) -> MetricMaskOutputs:
    """
    metric-mask
    
    Mask a metric file.
    
    By default, the output metric is a copy of the input metric, but with zeros
    wherever the mask metric is zero or negative. if -column is specified, the
    output contains only one column, the masked version of the specified input
    column.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricMaskOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_MASK_METADATA)
    params = execution.params(params)
    cargs = metric_mask_cargs(params, execution)
    ret = metric_mask_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_mask(
    metric: InputPathType,
    mask: InputPathType,
    metric_out: str,
    opt_column_column: str | None = None,
    runner: Runner | None = None,
) -> MetricMaskOutputs:
    """
    metric-mask
    
    Mask a metric file.
    
    By default, the output metric is a copy of the input metric, but with zeros
    wherever the mask metric is zero or negative. if -column is specified, the
    output contains only one column, the masked version of the specified input
    column.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        metric: the input metric.
        mask: the mask metric.
        metric_out: the output metric.
        opt_column_column: select a single column: the column number or name.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricMaskOutputs`).
    """
    params = metric_mask_params(
        metric=metric,
        mask=mask,
        metric_out=metric_out,
        opt_column_column=opt_column_column,
    )
    return metric_mask_execute(params, runner)


__all__ = [
    "METRIC_MASK_METADATA",
    "MetricMaskOutputs",
    "metric_mask",
    "metric_mask_execute",
    "metric_mask_params",
]
