# 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="681850b8635d1fb30c276619483f247b1d36e566.workbench",
    name="metric-mask",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_MetricMaskParamsDictNoTag = typing.TypedDict('_MetricMaskParamsDictNoTag', {
    "metric": InputPathType,
    "mask": InputPathType,
    "metric-out": str,
    "column": typing.NotRequired[str | None],
})
MetricMaskParamsDictTagged = typing.TypedDict('MetricMaskParamsDictTagged', {
    "@type": typing.Literal["workbench/metric-mask"],
    "metric": InputPathType,
    "mask": InputPathType,
    "metric-out": str,
    "column": typing.NotRequired[str | None],
})
MetricMaskParamsDict = _MetricMaskParamsDictNoTag | MetricMaskParamsDictTagged


class MetricMaskOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricMaskParamsDict(...)`.
    """
    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,
    column: str | None = None,
) -> MetricMaskParamsDictTagged:
    """
    Build parameters.
    
    Args:
        metric: the input metric.
        mask: the mask metric.
        metric_out: the output metric.
        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 column is not None:
        params["column"] = column
    return params


def metric_mask_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MetricMaskParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("metric", None) is None:
        raise StyxValidationError("`metric` must not be None")
    if not isinstance(params["metric"], (pathlib.Path, str)):
        raise StyxValidationError(f'`metric` has the wrong type: Received `{type(params.get("metric", None))}` expected `InputPathType`')
    if params.get("mask", None) is None:
        raise StyxValidationError("`mask` must not be None")
    if not isinstance(params["mask"], (pathlib.Path, str)):
        raise StyxValidationError(f'`mask` has the wrong type: Received `{type(params.get("mask", None))}` expected `InputPathType`')
    if params.get("metric-out", None) is None:
        raise StyxValidationError("`metric-out` must not be None")
    if not isinstance(params["metric-out"], str):
        raise StyxValidationError(f'`metric-out` has the wrong type: Received `{type(params.get("metric-out", None))}` expected `str`')
    if params.get("column", None) is not None:
        if not isinstance(params["column"], str):
            raise StyxValidationError(f'`column` has the wrong type: Received `{type(params.get("column", None))}` expected `str | None`')


def metric_mask_cargs(
    params: MetricMaskParamsDict,
    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.extend([
        "wb_command",
        "-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("column", None) is not None:
        cargs.extend([
            "-column",
            params.get("column", None)
        ])
    return cargs


def metric_mask_outputs(
    params: MetricMaskParamsDict,
    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: MetricMaskParamsDict,
    runner: Runner | None = None,
) -> MetricMaskOutputs:
    """
    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.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricMaskOutputs`).
    """
    metric_mask_validate(params)
    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,
    column: str | None = None,
    runner: Runner | None = None,
) -> MetricMaskOutputs:
    """
    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.
    
    Args:
        metric: the input metric.
        mask: the mask metric.
        metric_out: the output metric.
        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,
        column=column,
    )
    return metric_mask_execute(params, runner)


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