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

import typing
import pathlib
from styxdefs import *

GIFTI_LABEL_ADD_PREFIX_METADATA = Metadata(
    id="2050683cc2a3ac8267565a6d11706197f084954a.workbench",
    name="gifti-label-add-prefix",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_GiftiLabelAddPrefixParamsDictNoTag = typing.TypedDict('_GiftiLabelAddPrefixParamsDictNoTag', {
    "label-in": InputPathType,
    "prefix": str,
    "label-out": str,
})
GiftiLabelAddPrefixParamsDictTagged = typing.TypedDict('GiftiLabelAddPrefixParamsDictTagged', {
    "@type": typing.Literal["workbench/gifti-label-add-prefix"],
    "label-in": InputPathType,
    "prefix": str,
    "label-out": str,
})
GiftiLabelAddPrefixParamsDict = _GiftiLabelAddPrefixParamsDictNoTag | GiftiLabelAddPrefixParamsDictTagged


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


def gifti_label_add_prefix_params(
    label_in: InputPathType,
    prefix: str,
    label_out: str,
) -> GiftiLabelAddPrefixParamsDictTagged:
    """
    Build parameters.
    
    Args:
        label_in: the input label file.
        prefix: the prefix string to add.
        label_out: the output label file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/gifti-label-add-prefix",
        "label-in": label_in,
        "prefix": prefix,
        "label-out": label_out,
    }
    return params


def gifti_label_add_prefix_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `GiftiLabelAddPrefixParamsDict` 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("prefix", None) is None:
        raise StyxValidationError("`prefix` must not be None")
    if not isinstance(params["prefix"], str):
        raise StyxValidationError(f'`prefix` has the wrong type: Received `{type(params.get("prefix", None))}` expected `str`')
    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`')


def gifti_label_add_prefix_cargs(
    params: GiftiLabelAddPrefixParamsDict,
    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-add-prefix"
    ])
    cargs.append(execution.input_file(params.get("label-in", None)))
    cargs.append(params.get("prefix", None))
    cargs.append(params.get("label-out", None))
    return cargs


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


def gifti_label_add_prefix_execute(
    params: GiftiLabelAddPrefixParamsDict,
    runner: Runner | None = None,
) -> GiftiLabelAddPrefixOutputs:
    """
    ADD PREFIX TO ALL LABEL NAMES IN A GIFTI LABEL FILE.
    
    For each label other than '???', prepend <prefix> to the label name.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GiftiLabelAddPrefixOutputs`).
    """
    gifti_label_add_prefix_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(GIFTI_LABEL_ADD_PREFIX_METADATA)
    params = execution.params(params)
    cargs = gifti_label_add_prefix_cargs(params, execution)
    ret = gifti_label_add_prefix_outputs(params, execution)
    execution.run(cargs)
    return ret


def gifti_label_add_prefix(
    label_in: InputPathType,
    prefix: str,
    label_out: str,
    runner: Runner | None = None,
) -> GiftiLabelAddPrefixOutputs:
    """
    ADD PREFIX TO ALL LABEL NAMES IN A GIFTI LABEL FILE.
    
    For each label other than '???', prepend <prefix> to the label name.
    
    Args:
        label_in: the input label file.
        prefix: the prefix string to add.
        label_out: the output label file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `GiftiLabelAddPrefixOutputs`).
    """
    params = gifti_label_add_prefix_params(
        label_in=label_in,
        prefix=prefix,
        label_out=label_out,
    )
    return gifti_label_add_prefix_execute(params, runner)


__all__ = [
    "GIFTI_LABEL_ADD_PREFIX_METADATA",
    "GiftiLabelAddPrefixOutputs",
    "GiftiLabelAddPrefixParamsDict",
    "GiftiLabelAddPrefixParamsDictTagged",
    "gifti_label_add_prefix",
    "gifti_label_add_prefix_execute",
    "gifti_label_add_prefix_params",
]
