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

import typing
import pathlib
from styxdefs import *

CIFTI_LABEL_TO_ROI_METADATA = Metadata(
    id="404b13c7f6d3d80cd95caa08b411c3b50061d9cb.boutiques",
    name="cifti-label-to-roi",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiLabelToRoiParameters = typing.TypedDict('CiftiLabelToRoiParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-label-to-roi"]],
    "label_in": InputPathType,
    "scalar_out": str,
    "opt_name_label_name": typing.NotRequired[str | None],
    "opt_key_label_key": typing.NotRequired[int | None],
    "opt_map_map": typing.NotRequired[str | None],
})
CiftiLabelToRoiParametersTagged = typing.TypedDict('CiftiLabelToRoiParametersTagged', {
    "@type": typing.Literal["workbench/cifti-label-to-roi"],
    "label_in": InputPathType,
    "scalar_out": str,
    "opt_name_label_name": typing.NotRequired[str | None],
    "opt_key_label_key": typing.NotRequired[int | None],
    "opt_map_map": typing.NotRequired[str | None],
})


class CiftiLabelToRoiOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiLabelToRoiParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    scalar_out: OutputPathType
    """the output cifti scalar file"""


def cifti_label_to_roi_params(
    label_in: InputPathType,
    scalar_out: str,
    opt_name_label_name: str | None = None,
    opt_key_label_key: int | None = None,
    opt_map_map: str | None = None,
) -> CiftiLabelToRoiParametersTagged:
    """
    Build parameters.
    
    Args:
        label_in: the input cifti label file.
        scalar_out: the output cifti scalar file.
        opt_name_label_name: select label by name: the label name that you want\
            an roi of.
        opt_key_label_key: select label by key: the label key that you want an\
            roi of.
        opt_map_map: select a single label map to use: the map number or name.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-label-to-roi",
        "label_in": label_in,
        "scalar_out": scalar_out,
    }
    if opt_name_label_name is not None:
        params["opt_name_label_name"] = opt_name_label_name
    if opt_key_label_key is not None:
        params["opt_key_label_key"] = opt_key_label_key
    if opt_map_map is not None:
        params["opt_map_map"] = opt_map_map
    return params


def cifti_label_to_roi_cargs(
    params: CiftiLabelToRoiParameters,
    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.append("wb_command")
    cargs.append("-cifti-label-to-roi")
    cargs.append(execution.input_file(params.get("label_in", None)))
    cargs.append(params.get("scalar_out", None))
    if params.get("opt_name_label_name", None) is not None:
        cargs.extend([
            "-name",
            params.get("opt_name_label_name", None)
        ])
    if params.get("opt_key_label_key", None) is not None:
        cargs.extend([
            "-key",
            str(params.get("opt_key_label_key", None))
        ])
    if params.get("opt_map_map", None) is not None:
        cargs.extend([
            "-map",
            params.get("opt_map_map", None)
        ])
    return cargs


def cifti_label_to_roi_outputs(
    params: CiftiLabelToRoiParameters,
    execution: Execution,
) -> CiftiLabelToRoiOutputs:
    """
    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 = CiftiLabelToRoiOutputs(
        root=execution.output_file("."),
        scalar_out=execution.output_file(params.get("scalar_out", None)),
    )
    return ret


def cifti_label_to_roi_execute(
    params: CiftiLabelToRoiParameters,
    runner: Runner | None = None,
) -> CiftiLabelToRoiOutputs:
    """
    cifti-label-to-roi
    
    Make a cifti label into an roi.
    
    For each map in <label-in>, a map is created in <scalar-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>.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelToRoiOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_LABEL_TO_ROI_METADATA)
    params = execution.params(params)
    cargs = cifti_label_to_roi_cargs(params, execution)
    ret = cifti_label_to_roi_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_label_to_roi(
    label_in: InputPathType,
    scalar_out: str,
    opt_name_label_name: str | None = None,
    opt_key_label_key: int | None = None,
    opt_map_map: str | None = None,
    runner: Runner | None = None,
) -> CiftiLabelToRoiOutputs:
    """
    cifti-label-to-roi
    
    Make a cifti label into an roi.
    
    For each map in <label-in>, a map is created in <scalar-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>.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        label_in: the input cifti label file.
        scalar_out: the output cifti scalar file.
        opt_name_label_name: select label by name: the label name that you want\
            an roi of.
        opt_key_label_key: select label by key: the label key that you want an\
            roi of.
        opt_map_map: select a single label map to use: the map number or name.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelToRoiOutputs`).
    """
    params = cifti_label_to_roi_params(
        label_in=label_in,
        scalar_out=scalar_out,
        opt_name_label_name=opt_name_label_name,
        opt_key_label_key=opt_key_label_key,
        opt_map_map=opt_map_map,
    )
    return cifti_label_to_roi_execute(params, runner)


__all__ = [
    "CIFTI_LABEL_TO_ROI_METADATA",
    "CiftiLabelToRoiOutputs",
    "cifti_label_to_roi",
    "cifti_label_to_roi_execute",
    "cifti_label_to_roi_params",
]
