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

import typing
import pathlib
from styxdefs import *

LABELCONVERT_METADATA = Metadata(
    id="5aa09ff9ec4b21693b7d07b8329c2bc641669b7c.boutiques",
    name="labelconvert",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_LabelconvertConfigParamsDictNoTag = typing.TypedDict('_LabelconvertConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
LabelconvertConfigParamsDictTagged = typing.TypedDict('LabelconvertConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
LabelconvertConfigParamsDict = _LabelconvertConfigParamsDictNoTag | LabelconvertConfigParamsDictTagged


_LabelconvertParamsDictNoTag = typing.TypedDict('_LabelconvertParamsDictNoTag', {
    "spine": typing.NotRequired[InputPathType | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[LabelconvertConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "path_in": InputPathType,
    "lut_in": InputPathType,
    "lut_out": InputPathType,
    "image_out": str,
})
LabelconvertParamsDictTagged = typing.TypedDict('LabelconvertParamsDictTagged', {
    "@type": typing.Literal["mrtrix/labelconvert"],
    "spine": typing.NotRequired[InputPathType | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[LabelconvertConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "path_in": InputPathType,
    "lut_in": InputPathType,
    "lut_out": InputPathType,
    "image_out": str,
})
LabelconvertParamsDict = _LabelconvertParamsDictNoTag | LabelconvertParamsDictTagged


def labelconvert_config(
    key: str,
    value: str,
) -> LabelconvertConfigParamsDictTagged:
    """
    Build parameters.
    
    Args:
        key: temporarily set the value of an MRtrix config file entry.
        value: temporarily set the value of an MRtrix config file entry.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "config",
        "key": key,
        "value": value,
    }
    return params


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


def labelconvert_config_cargs(
    params: LabelconvertConfigParamsDict,
    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("-config")
    cargs.append(params.get("key", None))
    cargs.append(params.get("value", None))
    return cargs


class LabelconvertOutputs(typing.NamedTuple):
    """
    Output object returned when calling `LabelconvertParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    image_out: OutputPathType
    """the output image"""


def labelconvert_params(
    path_in: InputPathType,
    lut_in: InputPathType,
    lut_out: InputPathType,
    image_out: str,
    spine: InputPathType | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[LabelconvertConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> LabelconvertParamsDictTagged:
    """
    Build parameters.
    
    Args:
        path_in: the input image.
        lut_in: the connectome lookup table corresponding to the input image.
        lut_out: the target connectome lookup table for the output image.
        image_out: the output image.
        spine: provide a manually-defined segmentation of the base of the spine\
            where the streamlines terminate, so that this can become a node in the\
            connection matrix.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mrtrix/labelconvert",
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "path_in": path_in,
        "lut_in": lut_in,
        "lut_out": lut_out,
        "image_out": image_out,
    }
    if spine is not None:
        params["spine"] = spine
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def labelconvert_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `LabelconvertParamsDict` 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("spine", None) is not None:
        if not isinstance(params["spine"], (pathlib.Path, str)):
            raise StyxValidationError(f'`spine` has the wrong type: Received `{type(params.get("spine", None))}` expected `InputPathType | None`')
    if params.get("info", False) is None:
        raise StyxValidationError("`info` must not be None")
    if not isinstance(params["info"], bool):
        raise StyxValidationError(f'`info` has the wrong type: Received `{type(params.get("info", False))}` expected `bool`')
    if params.get("quiet", False) is None:
        raise StyxValidationError("`quiet` must not be None")
    if not isinstance(params["quiet"], bool):
        raise StyxValidationError(f'`quiet` has the wrong type: Received `{type(params.get("quiet", False))}` expected `bool`')
    if params.get("debug", False) is None:
        raise StyxValidationError("`debug` must not be None")
    if not isinstance(params["debug"], bool):
        raise StyxValidationError(f'`debug` has the wrong type: Received `{type(params.get("debug", False))}` expected `bool`')
    if params.get("force", False) is None:
        raise StyxValidationError("`force` must not be None")
    if not isinstance(params["force"], bool):
        raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", False))}` expected `bool`')
    if params.get("nthreads", None) is not None:
        if not isinstance(params["nthreads"], int):
            raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `int | None`')
    if params.get("config", None) is not None:
        if not isinstance(params["config"], list):
            raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[LabelconvertConfigParamsDict] | None`')
        for e in params["config"]:
            labelconvert_config_validate(e)
    if params.get("help", False) is None:
        raise StyxValidationError("`help` must not be None")
    if not isinstance(params["help"], bool):
        raise StyxValidationError(f'`help` has the wrong type: Received `{type(params.get("help", False))}` expected `bool`')
    if params.get("version", False) is None:
        raise StyxValidationError("`version` must not be None")
    if not isinstance(params["version"], bool):
        raise StyxValidationError(f'`version` has the wrong type: Received `{type(params.get("version", False))}` expected `bool`')
    if params.get("path_in", None) is None:
        raise StyxValidationError("`path_in` must not be None")
    if not isinstance(params["path_in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`path_in` has the wrong type: Received `{type(params.get("path_in", None))}` expected `InputPathType`')
    if params.get("lut_in", None) is None:
        raise StyxValidationError("`lut_in` must not be None")
    if not isinstance(params["lut_in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`lut_in` has the wrong type: Received `{type(params.get("lut_in", None))}` expected `InputPathType`')
    if params.get("lut_out", None) is None:
        raise StyxValidationError("`lut_out` must not be None")
    if not isinstance(params["lut_out"], (pathlib.Path, str)):
        raise StyxValidationError(f'`lut_out` has the wrong type: Received `{type(params.get("lut_out", None))}` expected `InputPathType`')
    if params.get("image_out", None) is None:
        raise StyxValidationError("`image_out` must not be None")
    if not isinstance(params["image_out"], str):
        raise StyxValidationError(f'`image_out` has the wrong type: Received `{type(params.get("image_out", None))}` expected `str`')


def labelconvert_cargs(
    params: LabelconvertParamsDict,
    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("labelconvert")
    if params.get("spine", None) is not None:
        cargs.extend([
            "-spine",
            execution.input_file(params.get("spine", None))
        ])
    if params.get("info", False):
        cargs.append("-info")
    if params.get("quiet", False):
        cargs.append("-quiet")
    if params.get("debug", False):
        cargs.append("-debug")
    if params.get("force", False):
        cargs.append("-force")
    if params.get("nthreads", None) is not None:
        cargs.extend([
            "-nthreads",
            str(params.get("nthreads", None))
        ])
    if params.get("config", None) is not None:
        cargs.extend([a for c in [labelconvert_config_cargs(s, execution) for s in params.get("config", None)] for a in c])
    if params.get("help", False):
        cargs.append("-help")
    if params.get("version", False):
        cargs.append("-version")
    cargs.append(execution.input_file(params.get("path_in", None)))
    cargs.append(execution.input_file(params.get("lut_in", None)))
    cargs.append(execution.input_file(params.get("lut_out", None)))
    cargs.append(params.get("image_out", None))
    return cargs


def labelconvert_outputs(
    params: LabelconvertParamsDict,
    execution: Execution,
) -> LabelconvertOutputs:
    """
    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 = LabelconvertOutputs(
        root=execution.output_file("."),
        image_out=execution.output_file(params.get("image_out", None)),
    )
    return ret


def labelconvert_execute(
    params: LabelconvertParamsDict,
    runner: Runner | None = None,
) -> LabelconvertOutputs:
    """
    labelconvert
    
    Convert a connectome node image from one lookup table to another.
    
    Typical usage is to convert a parcellation image provided by some other
    software, based on the lookup table provided by that software, to conform to
    a new lookup table, particularly one where the node indices increment from
    1, in preparation for connectome construction; examples of such target
    lookup table files are provided in share//mrtrix3//labelconvert//, but can
    be created by the user to provide the desired node set // ordering //
    colours.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `LabelconvertOutputs`).
    """
    labelconvert_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(LABELCONVERT_METADATA)
    params = execution.params(params)
    cargs = labelconvert_cargs(params, execution)
    ret = labelconvert_outputs(params, execution)
    execution.run(cargs)
    return ret


def labelconvert(
    path_in: InputPathType,
    lut_in: InputPathType,
    lut_out: InputPathType,
    image_out: str,
    spine: InputPathType | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[LabelconvertConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> LabelconvertOutputs:
    """
    labelconvert
    
    Convert a connectome node image from one lookup table to another.
    
    Typical usage is to convert a parcellation image provided by some other
    software, based on the lookup table provided by that software, to conform to
    a new lookup table, particularly one where the node indices increment from
    1, in preparation for connectome construction; examples of such target
    lookup table files are provided in share//mrtrix3//labelconvert//, but can
    be created by the user to provide the desired node set // ordering //
    colours.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        path_in: the input image.
        lut_in: the connectome lookup table corresponding to the input image.
        lut_out: the target connectome lookup table for the output image.
        image_out: the output image.
        spine: provide a manually-defined segmentation of the base of the spine\
            where the streamlines terminate, so that this can become a node in the\
            connection matrix.
        info: display information messages.
        quiet: do not display information messages or progress status;\
            alternatively, this can be achieved by setting the MRTRIX_QUIET\
            environment variable to a non-empty string.
        debug: display debugging messages.
        force: force overwrite of output files (caution: using the same file as\
            input and output might cause unexpected behaviour).
        nthreads: use this number of threads in multi-threaded applications\
            (set to 0 to disable multi-threading).
        config: temporarily set the value of an MRtrix config file entry.
        help_: display this information page and exit.
        version: display version information and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `LabelconvertOutputs`).
    """
    params = labelconvert_params(
        spine=spine,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        path_in=path_in,
        lut_in=lut_in,
        lut_out=lut_out,
        image_out=image_out,
    )
    return labelconvert_execute(params, runner)


__all__ = [
    "LABELCONVERT_METADATA",
    "LabelconvertConfigParamsDict",
    "LabelconvertConfigParamsDictTagged",
    "LabelconvertOutputs",
    "LabelconvertParamsDict",
    "LabelconvertParamsDictTagged",
    "labelconvert",
    "labelconvert_config",
    "labelconvert_execute",
    "labelconvert_params",
]
