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

import typing
import pathlib
from styxdefs import *

VOLUME_ALL_LABELS_TO_ROIS_METADATA = Metadata(
    id="25c70d1f4cda55f2df56316907bd5e6bb29642d1.workbench",
    name="volume-all-labels-to-rois",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_VolumeAllLabelsToRoisParamsDictNoTag = typing.TypedDict('_VolumeAllLabelsToRoisParamsDictNoTag', {
    "label-in": InputPathType,
    "map": str,
    "volume-out": str,
})
VolumeAllLabelsToRoisParamsDictTagged = typing.TypedDict('VolumeAllLabelsToRoisParamsDictTagged', {
    "@type": typing.Literal["workbench/volume-all-labels-to-rois"],
    "label-in": InputPathType,
    "map": str,
    "volume-out": str,
})
VolumeAllLabelsToRoisParamsDict = _VolumeAllLabelsToRoisParamsDictNoTag | VolumeAllLabelsToRoisParamsDictTagged


class VolumeAllLabelsToRoisOutputs(typing.NamedTuple):
    """
    Output object returned when calling `VolumeAllLabelsToRoisParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    volume_out: OutputPathType
    """the output volume file"""


def volume_all_labels_to_rois_params(
    label_in: InputPathType,
    map_: str,
    volume_out: str,
) -> VolumeAllLabelsToRoisParamsDictTagged:
    """
    Build parameters.
    
    Args:
        label_in: the input volume label file.
        map_: the number or name of the label map to use.
        volume_out: the output volume file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-all-labels-to-rois",
        "label-in": label_in,
        "map": map_,
        "volume-out": volume_out,
    }
    return params


def volume_all_labels_to_rois_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `VolumeAllLabelsToRoisParamsDict` 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-in", None) is None:
        raise StyxValidationError("`label-in` must not be None")
    if not isinstance(params["label-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`label-in` has the wrong type: Received `{type(params.get("label-in", None))}` expected `InputPathType`')
    if params.get("map", None) is None:
        raise StyxValidationError("`map` must not be None")
    if not isinstance(params["map"], str):
        raise StyxValidationError(f'`map` has the wrong type: Received `{type(params.get("map", None))}` expected `str`')
    if params.get("volume-out", None) is None:
        raise StyxValidationError("`volume-out` must not be None")
    if not isinstance(params["volume-out"], str):
        raise StyxValidationError(f'`volume-out` has the wrong type: Received `{type(params.get("volume-out", None))}` expected `str`')


def volume_all_labels_to_rois_cargs(
    params: VolumeAllLabelsToRoisParamsDict,
    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",
        "-volume-all-labels-to-rois"
    ])
    cargs.append(execution.input_file(params.get("label-in", None)))
    cargs.append(params.get("map", None))
    cargs.append(params.get("volume-out", None))
    return cargs


def volume_all_labels_to_rois_outputs(
    params: VolumeAllLabelsToRoisParamsDict,
    execution: Execution,
) -> VolumeAllLabelsToRoisOutputs:
    """
    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 = VolumeAllLabelsToRoisOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume-out", None)),
    )
    return ret


def volume_all_labels_to_rois_execute(
    params: VolumeAllLabelsToRoisParamsDict,
    runner: Runner | None = None,
) -> VolumeAllLabelsToRoisOutputs:
    """
    MAKE ROIS FROM ALL LABELS IN A VOLUME FRAME.
    
    The output volume has a frame for each label in the specified input frame,
    other than the ??? label, each of which contains an ROI of all voxels that
    are set to the corresponding label.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeAllLabelsToRoisOutputs`).
    """
    volume_all_labels_to_rois_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_ALL_LABELS_TO_ROIS_METADATA)
    params = execution.params(params)
    cargs = volume_all_labels_to_rois_cargs(params, execution)
    ret = volume_all_labels_to_rois_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_all_labels_to_rois(
    label_in: InputPathType,
    map_: str,
    volume_out: str,
    runner: Runner | None = None,
) -> VolumeAllLabelsToRoisOutputs:
    """
    MAKE ROIS FROM ALL LABELS IN A VOLUME FRAME.
    
    The output volume has a frame for each label in the specified input frame,
    other than the ??? label, each of which contains an ROI of all voxels that
    are set to the corresponding label.
    
    Args:
        label_in: the input volume label file.
        map_: the number or name of the label map to use.
        volume_out: the output volume file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeAllLabelsToRoisOutputs`).
    """
    params = volume_all_labels_to_rois_params(
        label_in=label_in,
        map_=map_,
        volume_out=volume_out,
    )
    return volume_all_labels_to_rois_execute(params, runner)


__all__ = [
    "VOLUME_ALL_LABELS_TO_ROIS_METADATA",
    "VolumeAllLabelsToRoisOutputs",
    "VolumeAllLabelsToRoisParamsDict",
    "VolumeAllLabelsToRoisParamsDictTagged",
    "volume_all_labels_to_rois",
    "volume_all_labels_to_rois_execute",
    "volume_all_labels_to_rois_params",
]
