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

import typing
import pathlib
from styxdefs import *

GIFTI_LABEL_TO_ROI_METADATA = Metadata(
    id="82549fa4f4d713245781e307c4dd75baad9fe47c.workbench",
    name="gifti-label-to-roi",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_GiftiLabelToRoiParamsDictNoTag = typing.TypedDict('_GiftiLabelToRoiParamsDictNoTag', {
    "label-in": InputPathType,
    "metric-out": str,
    "map": typing.NotRequired[str | None],
    "label-key": typing.NotRequired[int | None],
    "label-name": typing.NotRequired[str | None],
})
GiftiLabelToRoiParamsDictTagged = typing.TypedDict('GiftiLabelToRoiParamsDictTagged', {
    "@type": typing.Literal["workbench/gifti-label-to-roi"],
    "label-in": InputPathType,
    "metric-out": str,
    "map": typing.NotRequired[str | None],
    "label-key": typing.NotRequired[int | None],
    "label-name": typing.NotRequired[str | None],
})
GiftiLabelToRoiParamsDict = _GiftiLabelToRoiParamsDictNoTag | GiftiLabelToRoiParamsDictTagged


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


def gifti_label_to_roi_params(
    label_in: InputPathType,
    metric_out: str,
    map_: str | None = None,
    label_key: int | None = None,
    label_name: str | None = None,
) -> GiftiLabelToRoiParamsDictTagged:
    """
    Build parameters.
    
    Args:
        label_in: the input gifti label file.
        metric_out: the output metric file.
        map_: select a single label map to use\
            \
            the map number or name.
        label_key: select label by key\
            \
            the label key that you want an roi of.
        label_name: select label by name\
            \
            the label name that you want an roi of.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/gifti-label-to-roi",
        "label-in": label_in,
        "metric-out": metric_out,
    }
    if map_ is not None:
        params["map"] = map_
    if label_key is not None:
        params["label-key"] = label_key
    if label_name is not None:
        params["label-name"] = label_name
    return params


def gifti_label_to_roi_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `GiftiLabelToRoiParamsDict` 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("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("map", None) is not None:
        if not isinstance(params["map"], str):
            raise StyxValidationError(f'`map` has the wrong type: Received `{type(params.get("map", None))}` expected `str | None`')
    if params.get("label-key", None) is not None:
        if not isinstance(params["label-key"], int):
            raise StyxValidationError(f'`label-key` has the wrong type: Received `{type(params.get("label-key", None))}` expected `int | None`')
    if params.get("label-name", None) is not None:
        if not isinstance(params["label-name"], str):
            raise StyxValidationError(f'`label-name` has the wrong type: Received `{type(params.get("label-name", None))}` expected `str | None`')


def gifti_label_to_roi_cargs(
    params: GiftiLabelToRoiParamsDict,
    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-label-to-roi"
    ])
    cargs.append(execution.input_file(params.get("label-in", None)))
    cargs.append(params.get("metric-out", None))
    if params.get("map", None) is not None:
        cargs.extend([
            "-map",
            params.get("map", None)
        ])
    if params.get("label-key", None) is not None:
        cargs.extend([
            "-key",
            str(params.get("label-key", None))
        ])
    if params.get("label-name", None) is not None:
        cargs.extend([
            "-name",
            params.get("label-name", None)
        ])
    return cargs


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


def gifti_label_to_roi_execute(
    params: GiftiLabelToRoiParamsDict,
    runner: Runner | None = None,
) -> GiftiLabelToRoiOutputs:
    """
    MAKE A GIFTI LABEL INTO AN ROI METRIC.
    
    For each map in <label-in>, a map is created in <metric-out> where all
    locations labeled with <label-name> or with a key of <label-key> are given a
    value of 1, and all other locations are given 0. Exactly one of -name and
    -key must be specified. Specify -map to use only one map from <label-in>.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GiftiLabelToRoiOutputs`).
    """
    gifti_label_to_roi_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(GIFTI_LABEL_TO_ROI_METADATA)
    params = execution.params(params)
    cargs = gifti_label_to_roi_cargs(params, execution)
    ret = gifti_label_to_roi_outputs(params, execution)
    execution.run(cargs)
    return ret


def gifti_label_to_roi(
    label_in: InputPathType,
    metric_out: str,
    map_: str | None = None,
    label_key: int | None = None,
    label_name: str | None = None,
    runner: Runner | None = None,
) -> GiftiLabelToRoiOutputs:
    """
    MAKE A GIFTI LABEL INTO AN ROI METRIC.
    
    For each map in <label-in>, a map is created in <metric-out> where all
    locations labeled with <label-name> or with a key of <label-key> are given a
    value of 1, and all other locations are given 0. Exactly one of -name and
    -key must be specified. Specify -map to use only one map from <label-in>.
    
    Args:
        label_in: the input gifti label file.
        metric_out: the output metric file.
        map_: select a single label map to use\
            \
            the map number or name.
        label_key: select label by key\
            \
            the label key that you want an roi of.
        label_name: select label by name\
            \
            the label name that you want an roi of.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GiftiLabelToRoiOutputs`).
    """
    params = gifti_label_to_roi_params(
        label_in=label_in,
        metric_out=metric_out,
        map_=map_,
        label_key=label_key,
        label_name=label_name,
    )
    return gifti_label_to_roi_execute(params, runner)


__all__ = [
    "GIFTI_LABEL_TO_ROI_METADATA",
    "GiftiLabelToRoiOutputs",
    "GiftiLabelToRoiParamsDict",
    "GiftiLabelToRoiParamsDictTagged",
    "gifti_label_to_roi",
    "gifti_label_to_roi_execute",
    "gifti_label_to_roi_params",
]
