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

import typing
import pathlib
from styxdefs import *

GIFTI_ALL_LABELS_TO_ROIS_METADATA = Metadata(
    id="0e399afa8268c4aa88310407830c9ce63af9480a.workbench",
    name="gifti-all-labels-to-rois",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_GiftiAllLabelsToRoisParamsDictNoTag = typing.TypedDict('_GiftiAllLabelsToRoisParamsDictNoTag', {
    "label-in": InputPathType,
    "map": str,
    "metric-out": str,
})
GiftiAllLabelsToRoisParamsDictTagged = typing.TypedDict('GiftiAllLabelsToRoisParamsDictTagged', {
    "@type": typing.Literal["workbench/gifti-all-labels-to-rois"],
    "label-in": InputPathType,
    "map": str,
    "metric-out": str,
})
GiftiAllLabelsToRoisParamsDict = _GiftiAllLabelsToRoisParamsDictNoTag | GiftiAllLabelsToRoisParamsDictTagged


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


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


def gifti_all_labels_to_rois_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `GiftiAllLabelsToRoisParamsDict` 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("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`')


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


def gifti_all_labels_to_rois_outputs(
    params: GiftiAllLabelsToRoisParamsDict,
    execution: Execution,
) -> GiftiAllLabelsToRoisOutputs:
    """
    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 = GiftiAllLabelsToRoisOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric-out", None)),
    )
    return ret


def gifti_all_labels_to_rois_execute(
    params: GiftiAllLabelsToRoisParamsDict,
    runner: Runner | None = None,
) -> GiftiAllLabelsToRoisOutputs:
    """
    MAKE ROIS FROM ALL LABELS IN A GIFTI COLUMN.
    
    The output metric file has a column for each label in the specified input
    map, other than the ??? label, each of which contains an ROI of all vertices
    that are set to the corresponding label.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GiftiAllLabelsToRoisOutputs`).
    """
    gifti_all_labels_to_rois_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(GIFTI_ALL_LABELS_TO_ROIS_METADATA)
    params = execution.params(params)
    cargs = gifti_all_labels_to_rois_cargs(params, execution)
    ret = gifti_all_labels_to_rois_outputs(params, execution)
    execution.run(cargs)
    return ret


def gifti_all_labels_to_rois(
    label_in: InputPathType,
    map_: str,
    metric_out: str,
    runner: Runner | None = None,
) -> GiftiAllLabelsToRoisOutputs:
    """
    MAKE ROIS FROM ALL LABELS IN A GIFTI COLUMN.
    
    The output metric file has a column for each label in the specified input
    map, other than the ??? label, each of which contains an ROI of all vertices
    that are set to the corresponding label.
    
    Args:
        label_in: the input gifti label file.
        map_: the number or name of the label map to use.
        metric_out: the output metric file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GiftiAllLabelsToRoisOutputs`).
    """
    params = gifti_all_labels_to_rois_params(
        label_in=label_in,
        map_=map_,
        metric_out=metric_out,
    )
    return gifti_all_labels_to_rois_execute(params, runner)


__all__ = [
    "GIFTI_ALL_LABELS_TO_ROIS_METADATA",
    "GiftiAllLabelsToRoisOutputs",
    "GiftiAllLabelsToRoisParamsDict",
    "GiftiAllLabelsToRoisParamsDictTagged",
    "gifti_all_labels_to_rois",
    "gifti_all_labels_to_rois_execute",
    "gifti_all_labels_to_rois_params",
]
