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

import typing
import pathlib
from styxdefs import *

FIXEL2PEAKS_METADATA = Metadata(
    id="0d92be2b2e1ceff15fcfee87e64154e86fddb5a8.boutiques",
    name="fixel2peaks",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_Fixel2peaksConfigParamsDictNoTag = typing.TypedDict('_Fixel2peaksConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
Fixel2peaksConfigParamsDictTagged = typing.TypedDict('Fixel2peaksConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
Fixel2peaksConfigParamsDict = _Fixel2peaksConfigParamsDictNoTag | Fixel2peaksConfigParamsDictTagged


_Fixel2peaksVariousStringParamsDictNoTag = typing.TypedDict('_Fixel2peaksVariousStringParamsDictNoTag', {
    "obj": str,
})
Fixel2peaksVariousStringParamsDictTagged = typing.TypedDict('Fixel2peaksVariousStringParamsDictTagged', {
    "@type": typing.Literal["VariousString"],
    "obj": str,
})
Fixel2peaksVariousStringParamsDict = _Fixel2peaksVariousStringParamsDictNoTag | Fixel2peaksVariousStringParamsDictTagged


_Fixel2peaksVariousFileParamsDictNoTag = typing.TypedDict('_Fixel2peaksVariousFileParamsDictNoTag', {
    "obj": InputPathType,
})
Fixel2peaksVariousFileParamsDictTagged = typing.TypedDict('Fixel2peaksVariousFileParamsDictTagged', {
    "@type": typing.Literal["VariousFile"],
    "obj": InputPathType,
})
Fixel2peaksVariousFileParamsDict = _Fixel2peaksVariousFileParamsDictNoTag | Fixel2peaksVariousFileParamsDictTagged


_Fixel2peaksParamsDictNoTag = typing.TypedDict('_Fixel2peaksParamsDictNoTag', {
    "number": typing.NotRequired[int | None],
    "nan": bool,
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Fixel2peaksConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in": typing.Union[Fixel2peaksVariousStringParamsDictTagged, Fixel2peaksVariousFileParamsDictTagged],
    "out": str,
})
Fixel2peaksParamsDictTagged = typing.TypedDict('Fixel2peaksParamsDictTagged', {
    "@type": typing.Literal["mrtrix/fixel2peaks"],
    "number": typing.NotRequired[int | None],
    "nan": bool,
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[Fixel2peaksConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "in": typing.Union[Fixel2peaksVariousStringParamsDictTagged, Fixel2peaksVariousFileParamsDictTagged],
    "out": str,
})
Fixel2peaksParamsDict = _Fixel2peaksParamsDictNoTag | Fixel2peaksParamsDictTagged


def fixel2peaks_in_cargs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "VariousString": fixel2peaks_various_string_cargs,
        "VariousFile": fixel2peaks_various_file_cargs,
    }.get(t)


def fixel2peaks_in_validate_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get validate params function by command type.
    
    Args:
        t: Command type.
    Returns:
        Validate params function.
    """
    return {
        "VariousString": fixel2peaks_various_string_validate,
        "VariousFile": fixel2peaks_various_file_validate,
    }.get(t)


def fixel2peaks_config(
    key: str,
    value: str,
) -> Fixel2peaksConfigParamsDictTagged:
    """
    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 fixel2peaks_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Fixel2peaksConfigParamsDict` 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 fixel2peaks_config_cargs(
    params: Fixel2peaksConfigParamsDict,
    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


def fixel2peaks_various_string(
    obj: str,
) -> Fixel2peaksVariousStringParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: String object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousString",
        "obj": obj,
    }
    return params


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


def fixel2peaks_various_string_cargs(
    params: Fixel2peaksVariousStringParamsDict,
    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(params.get("obj", None))
    return cargs


def fixel2peaks_various_file(
    obj: InputPathType,
) -> Fixel2peaksVariousFileParamsDictTagged:
    """
    Build parameters.
    
    Args:
        obj: File object.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "VariousFile",
        "obj": obj,
    }
    return params


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


def fixel2peaks_various_file_cargs(
    params: Fixel2peaksVariousFileParamsDict,
    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(execution.input_file(params.get("obj", None)))
    return cargs


class Fixel2peaksOutputs(typing.NamedTuple):
    """
    Output object returned when calling `Fixel2peaksParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out: OutputPathType
    """the output peaks image"""


def fixel2peaks_params(
    in_: typing.Union[Fixel2peaksVariousStringParamsDictTagged, Fixel2peaksVariousFileParamsDictTagged],
    out: str,
    number: int | None = None,
    nan: bool = False,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Fixel2peaksConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> Fixel2peaksParamsDictTagged:
    """
    Build parameters.
    
    Args:
        in_: the input fixel information.
        out: the output peaks image.
        number: maximum number of fixels in each voxel (default: based on input\
            data).
        nan: fill excess peak data with NaNs rather than zeroes.
        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/fixel2peaks",
        "nan": nan,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "in": in_,
        "out": out,
    }
    if number is not None:
        params["number"] = number
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def fixel2peaks_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `Fixel2peaksParamsDict` 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("number", None) is not None:
        if not isinstance(params["number"], int):
            raise StyxValidationError(f'`number` has the wrong type: Received `{type(params.get("number", None))}` expected `int | None`')
    if params.get("nan", False) is None:
        raise StyxValidationError("`nan` must not be None")
    if not isinstance(params["nan"], bool):
        raise StyxValidationError(f'`nan` has the wrong type: Received `{type(params.get("nan", False))}` expected `bool`')
    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[Fixel2peaksConfigParamsDict] | None`')
        for e in params["config"]:
            fixel2peaks_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("in", None) is None:
        raise StyxValidationError("`in` must not be None")
    if not isinstance(params["in"], dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params["in"])}\'')
    if "@type" not in params["in"]:
        raise StyxValidationError("Params object is missing `@type`")
    if params["in"]["@type"] not in ["VariousString", "VariousFile"]:
        raise StyxValidationError("Parameter `in`s `@type` must be one of [\"VariousString\", \"VariousFile\"]")
    fixel2peaks_in_validate_dyn_fn(params["in"]["@type"])(params["in"])
    if params.get("out", None) is None:
        raise StyxValidationError("`out` must not be None")
    if not isinstance(params["out"], str):
        raise StyxValidationError(f'`out` has the wrong type: Received `{type(params.get("out", None))}` expected `str`')


def fixel2peaks_cargs(
    params: Fixel2peaksParamsDict,
    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("fixel2peaks")
    if params.get("number", None) is not None:
        cargs.extend([
            "-number",
            str(params.get("number", None))
        ])
    if params.get("nan", False):
        cargs.append("-nan")
    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 [fixel2peaks_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.extend(fixel2peaks_in_cargs_dyn_fn(params.get("in", None)["@type"])(params.get("in", None), execution))
    cargs.append(params.get("out", None))
    return cargs


def fixel2peaks_outputs(
    params: Fixel2peaksParamsDict,
    execution: Execution,
) -> Fixel2peaksOutputs:
    """
    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 = Fixel2peaksOutputs(
        root=execution.output_file("."),
        out=execution.output_file(params.get("out", None)),
    )
    return ret


def fixel2peaks_execute(
    params: Fixel2peaksParamsDict,
    runner: Runner | None = None,
) -> Fixel2peaksOutputs:
    """
    fixel2peaks
    
    Convert data in the fixel directory format into a 4D image of 3-vectors.
    
    If a fixel data file is provided as input, then the 3-vectors in the output
    image will be scaled based on the data in that file. If the input is instead
    the fixel directory, or the index or directions file, then all output
    3-vectors will possess unit norm.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Fixel2peaksOutputs`).
    """
    fixel2peaks_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(FIXEL2PEAKS_METADATA)
    params = execution.params(params)
    cargs = fixel2peaks_cargs(params, execution)
    ret = fixel2peaks_outputs(params, execution)
    execution.run(cargs)
    return ret


def fixel2peaks(
    in_: typing.Union[Fixel2peaksVariousStringParamsDictTagged, Fixel2peaksVariousFileParamsDictTagged],
    out: str,
    number: int | None = None,
    nan: bool = False,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[Fixel2peaksConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> Fixel2peaksOutputs:
    """
    fixel2peaks
    
    Convert data in the fixel directory format into a 4D image of 3-vectors.
    
    If a fixel data file is provided as input, then the 3-vectors in the output
    image will be scaled based on the data in that file. If the input is instead
    the fixel directory, or the index or directions file, then all output
    3-vectors will possess unit norm.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        in_: the input fixel information.
        out: the output peaks image.
        number: maximum number of fixels in each voxel (default: based on input\
            data).
        nan: fill excess peak data with NaNs rather than zeroes.
        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 `Fixel2peaksOutputs`).
    """
    params = fixel2peaks_params(
        number=number,
        nan=nan,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        in_=in_,
        out=out,
    )
    return fixel2peaks_execute(params, runner)


__all__ = [
    "FIXEL2PEAKS_METADATA",
    "Fixel2peaksConfigParamsDict",
    "Fixel2peaksConfigParamsDictTagged",
    "Fixel2peaksOutputs",
    "Fixel2peaksParamsDict",
    "Fixel2peaksParamsDictTagged",
    "Fixel2peaksVariousFileParamsDict",
    "Fixel2peaksVariousFileParamsDictTagged",
    "Fixel2peaksVariousStringParamsDict",
    "Fixel2peaksVariousStringParamsDictTagged",
    "fixel2peaks",
    "fixel2peaks_config",
    "fixel2peaks_execute",
    "fixel2peaks_params",
    "fixel2peaks_various_file",
    "fixel2peaks_various_string",
]
