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

import typing
import pathlib
from styxdefs import *

MRCOLOUR_METADATA = Metadata(
    id="9cd4b4f06262529bb32fb59ee13631275aef99fa.boutiques",
    name="mrcolour",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_MrcolourConfigParamsDictNoTag = typing.TypedDict('_MrcolourConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
MrcolourConfigParamsDictTagged = typing.TypedDict('MrcolourConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
MrcolourConfigParamsDict = _MrcolourConfigParamsDictNoTag | MrcolourConfigParamsDictTagged


_MrcolourParamsDictNoTag = typing.TypedDict('_MrcolourParamsDictNoTag', {
    "upper": typing.NotRequired[float | None],
    "lower": typing.NotRequired[float | None],
    "colour": typing.NotRequired[list[float] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrcolourConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "map": str,
    "output": str,
})
MrcolourParamsDictTagged = typing.TypedDict('MrcolourParamsDictTagged', {
    "@type": typing.Literal["mrtrix/mrcolour"],
    "upper": typing.NotRequired[float | None],
    "lower": typing.NotRequired[float | None],
    "colour": typing.NotRequired[list[float] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MrcolourConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "map": str,
    "output": str,
})
MrcolourParamsDict = _MrcolourParamsDictNoTag | MrcolourParamsDictTagged


def mrcolour_config(
    key: str,
    value: str,
) -> MrcolourConfigParamsDictTagged:
    """
    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 mrcolour_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrcolourConfigParamsDict` 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 mrcolour_config_cargs(
    params: MrcolourConfigParamsDict,
    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 MrcolourOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MrcolourParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """the output image"""


def mrcolour_params(
    input_: InputPathType,
    map_: str,
    output: str,
    upper: float | None = None,
    lower: float | None = None,
    colour: list[float] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrcolourConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> MrcolourParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: the input image.
        map_: the colourmap to apply; choices are:\
            gray,hot,cool,jet,inferno,viridis,pet,colour,rgb.
        output: the output image.
        upper: manually set the upper intensity of the colour mapping.
        lower: manually set the lower intensity of the colour mapping.
        colour: set the target colour for use of the 'colour' map (three\
            comma-separated floating-point values).
        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/mrcolour",
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "input": input_,
        "map": map_,
        "output": output,
    }
    if upper is not None:
        params["upper"] = upper
    if lower is not None:
        params["lower"] = lower
    if colour is not None:
        params["colour"] = colour
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def mrcolour_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MrcolourParamsDict` 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("upper", None) is not None:
        if not isinstance(params["upper"], (float, int)):
            raise StyxValidationError(f'`upper` has the wrong type: Received `{type(params.get("upper", None))}` expected `float | None`')
    if params.get("lower", None) is not None:
        if not isinstance(params["lower"], (float, int)):
            raise StyxValidationError(f'`lower` has the wrong type: Received `{type(params.get("lower", None))}` expected `float | None`')
    if params.get("colour", None) is not None:
        if not isinstance(params["colour"], list):
            raise StyxValidationError(f'`colour` has the wrong type: Received `{type(params.get("colour", None))}` expected `list[float] | None`')
        for e in params["colour"]:
            if not isinstance(e, (float, int)):
                raise StyxValidationError(f'`colour` has the wrong type: Received `{type(params.get("colour", None))}` expected `list[float] | 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[MrcolourConfigParamsDict] | None`')
        for e in params["config"]:
            mrcolour_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("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", 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("output", None) is None:
        raise StyxValidationError("`output` must not be None")
    if not isinstance(params["output"], str):
        raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str`')


def mrcolour_cargs(
    params: MrcolourParamsDict,
    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("mrcolour")
    if params.get("upper", None) is not None:
        cargs.extend([
            "-upper",
            str(params.get("upper", None))
        ])
    if params.get("lower", None) is not None:
        cargs.extend([
            "-lower",
            str(params.get("lower", None))
        ])
    if params.get("colour", None) is not None:
        cargs.extend([
            "-colour",
            ",".join(map(str, params.get("colour", 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 [mrcolour_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("input", None)))
    cargs.append(params.get("map", None))
    cargs.append(params.get("output", None))
    return cargs


def mrcolour_outputs(
    params: MrcolourParamsDict,
    execution: Execution,
) -> MrcolourOutputs:
    """
    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 = MrcolourOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


def mrcolour_execute(
    params: MrcolourParamsDict,
    runner: Runner | None = None,
) -> MrcolourOutputs:
    """
    mrcolour
    
    Apply a colour map to an image.
    
    Under typical usage, this command will receive as input ad 3D greyscale
    image, and output a 4D image with 3 volumes corresponding to red-green-blue
    components; other use cases are possible, and are described in more detail
    below.
    
    By default, the command will automatically determine the maximum and minimum
    intensities of the input image, and use that information to set the upper
    and lower bounds of the applied colourmap. This behaviour can be overridden
    by manually specifying these bounds using the -upper and -lower options
    respectively.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MrcolourOutputs`).
    """
    mrcolour_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRCOLOUR_METADATA)
    params = execution.params(params)
    cargs = mrcolour_cargs(params, execution)
    ret = mrcolour_outputs(params, execution)
    execution.run(cargs)
    return ret


def mrcolour(
    input_: InputPathType,
    map_: str,
    output: str,
    upper: float | None = None,
    lower: float | None = None,
    colour: list[float] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MrcolourConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MrcolourOutputs:
    """
    mrcolour
    
    Apply a colour map to an image.
    
    Under typical usage, this command will receive as input ad 3D greyscale
    image, and output a 4D image with 3 volumes corresponding to red-green-blue
    components; other use cases are possible, and are described in more detail
    below.
    
    By default, the command will automatically determine the maximum and minimum
    intensities of the input image, and use that information to set the upper
    and lower bounds of the applied colourmap. This behaviour can be overridden
    by manually specifying these bounds using the -upper and -lower options
    respectively.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        input_: the input image.
        map_: the colourmap to apply; choices are:\
            gray,hot,cool,jet,inferno,viridis,pet,colour,rgb.
        output: the output image.
        upper: manually set the upper intensity of the colour mapping.
        lower: manually set the lower intensity of the colour mapping.
        colour: set the target colour for use of the 'colour' map (three\
            comma-separated floating-point values).
        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 `MrcolourOutputs`).
    """
    params = mrcolour_params(
        upper=upper,
        lower=lower,
        colour=colour,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        input_=input_,
        map_=map_,
        output=output,
    )
    return mrcolour_execute(params, runner)


__all__ = [
    "MRCOLOUR_METADATA",
    "MrcolourConfigParamsDict",
    "MrcolourConfigParamsDictTagged",
    "MrcolourOutputs",
    "MrcolourParamsDict",
    "MrcolourParamsDictTagged",
    "mrcolour",
    "mrcolour_config",
    "mrcolour_execute",
    "mrcolour_params",
]
