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

import typing
import pathlib
from styxdefs import *

LABEL_MASK_METADATA = Metadata(
    id="8143b670e00529bec92d2236053b58d9bab6aa76.workbench",
    name="label-mask",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_LabelMaskParamsDictNoTag = typing.TypedDict('_LabelMaskParamsDictNoTag', {
    "label": InputPathType,
    "mask": InputPathType,
    "label-out": str,
    "column": typing.NotRequired[str | None],
})
LabelMaskParamsDictTagged = typing.TypedDict('LabelMaskParamsDictTagged', {
    "@type": typing.Literal["workbench/label-mask"],
    "label": InputPathType,
    "mask": InputPathType,
    "label-out": str,
    "column": typing.NotRequired[str | None],
})
LabelMaskParamsDict = _LabelMaskParamsDictNoTag | LabelMaskParamsDictTagged


class LabelMaskOutputs(typing.NamedTuple):
    """
    Output object returned when calling `LabelMaskParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    label_out: OutputPathType
    """the output label file"""


def label_mask_params(
    label: InputPathType,
    mask: InputPathType,
    label_out: str,
    column: str | None = None,
) -> LabelMaskParamsDictTagged:
    """
    Build parameters.
    
    Args:
        label: the label file to mask.
        mask: the mask metric.
        label_out: the output label file.
        column: select a single column\
            \
            the column number or name.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/label-mask",
        "label": label,
        "mask": mask,
        "label-out": label_out,
    }
    if column is not None:
        params["column"] = column
    return params


def label_mask_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `LabelMaskParamsDict` 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("label", None) is None:
        raise StyxValidationError("`label` must not be None")
    if not isinstance(params["label"], (pathlib.Path, str)):
        raise StyxValidationError(f'`label` has the wrong type: Received `{type(params.get("label", 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("label-out", None) is None:
        raise StyxValidationError("`label-out` must not be None")
    if not isinstance(params["label-out"], str):
        raise StyxValidationError(f'`label-out` has the wrong type: Received `{type(params.get("label-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 label_mask_cargs(
    params: LabelMaskParamsDict,
    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",
        "-label-mask"
    ])
    cargs.append(execution.input_file(params.get("label", None)))
    cargs.append(execution.input_file(params.get("mask", None)))
    cargs.append(params.get("label-out", None))
    if params.get("column", None) is not None:
        cargs.extend([
            "-column",
            params.get("column", None)
        ])
    return cargs


def label_mask_outputs(
    params: LabelMaskParamsDict,
    execution: Execution,
) -> LabelMaskOutputs:
    """
    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 = LabelMaskOutputs(
        root=execution.output_file("."),
        label_out=execution.output_file(params.get("label-out", None)),
    )
    return ret


def label_mask_execute(
    params: LabelMaskParamsDict,
    runner: Runner | None = None,
) -> LabelMaskOutputs:
    """
    MASK A LABEL FILE.
    
    By default, the output label is a copy of the input label, but with the
    'unused' label 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 `LabelMaskOutputs`).
    """
    label_mask_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(LABEL_MASK_METADATA)
    params = execution.params(params)
    cargs = label_mask_cargs(params, execution)
    ret = label_mask_outputs(params, execution)
    execution.run(cargs)
    return ret


def label_mask(
    label: InputPathType,
    mask: InputPathType,
    label_out: str,
    column: str | None = None,
    runner: Runner | None = None,
) -> LabelMaskOutputs:
    """
    MASK A LABEL FILE.
    
    By default, the output label is a copy of the input label, but with the
    'unused' label 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:
        label: the label file to mask.
        mask: the mask metric.
        label_out: the output label file.
        column: select a single column\
            \
            the column number or name.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `LabelMaskOutputs`).
    """
    params = label_mask_params(
        label=label,
        mask=mask,
        label_out=label_out,
        column=column,
    )
    return label_mask_execute(params, runner)


__all__ = [
    "LABEL_MASK_METADATA",
    "LabelMaskOutputs",
    "LabelMaskParamsDict",
    "LabelMaskParamsDictTagged",
    "label_mask",
    "label_mask_execute",
    "label_mask_params",
]
