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

import typing
import pathlib
from styxdefs import *

TCKSTATS_METADATA = Metadata(
    id="1c376e03915b6fa825105cf6a3a1f00bd7cafd03.boutiques",
    name="tckstats",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_TckstatsOutputParamsDictNoTag = typing.TypedDict('_TckstatsOutputParamsDictNoTag', {
    "field": str,
})
TckstatsOutputParamsDictTagged = typing.TypedDict('TckstatsOutputParamsDictTagged', {
    "@type": typing.Literal["output"],
    "field": str,
})
TckstatsOutputParamsDict = _TckstatsOutputParamsDictNoTag | TckstatsOutputParamsDictTagged


_TckstatsConfigParamsDictNoTag = typing.TypedDict('_TckstatsConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
TckstatsConfigParamsDictTagged = typing.TypedDict('TckstatsConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
TckstatsConfigParamsDict = _TckstatsConfigParamsDictNoTag | TckstatsConfigParamsDictTagged


_TckstatsParamsDictNoTag = typing.TypedDict('_TckstatsParamsDictNoTag', {
    "output": typing.NotRequired[list[TckstatsOutputParamsDict] | None],
    "histogram": typing.NotRequired[str | None],
    "dump": typing.NotRequired[str | None],
    "ignorezero": bool,
    "tck_weights_in": typing.NotRequired[InputPathType | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[TckstatsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "tracks_in": InputPathType,
})
TckstatsParamsDictTagged = typing.TypedDict('TckstatsParamsDictTagged', {
    "@type": typing.Literal["mrtrix/tckstats"],
    "output": typing.NotRequired[list[TckstatsOutputParamsDict] | None],
    "histogram": typing.NotRequired[str | None],
    "dump": typing.NotRequired[str | None],
    "ignorezero": bool,
    "tck_weights_in": typing.NotRequired[InputPathType | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[TckstatsConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "tracks_in": InputPathType,
})
TckstatsParamsDict = _TckstatsParamsDictNoTag | TckstatsParamsDictTagged


def tckstats_output(
    field: str,
) -> TckstatsOutputParamsDictTagged:
    """
    Build parameters.
    
    Args:
        field: output only the field specified. Multiple such options can be\
            supplied if required. Choices are: mean, median, std, min, max, count.\
            Useful for use in scripts.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "output",
        "field": field,
    }
    return params


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


def tckstats_output_cargs(
    params: TckstatsOutputParamsDict,
    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("-output")
    cargs.append(params.get("field", None))
    return cargs


def tckstats_config(
    key: str,
    value: str,
) -> TckstatsConfigParamsDictTagged:
    """
    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 tckstats_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `TckstatsConfigParamsDict` 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 tckstats_config_cargs(
    params: TckstatsConfigParamsDict,
    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 TckstatsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `TckstatsParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    histogram: OutputPathType | None
    """output a histogram of streamline lengths """
    dump: OutputPathType | None
    """dump the streamlines lengths to a text file """


def tckstats_params(
    tracks_in: InputPathType,
    output: list[TckstatsOutputParamsDict] | None = None,
    histogram: str | None = None,
    dump: str | None = None,
    ignorezero: bool = False,
    tck_weights_in: InputPathType | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[TckstatsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> TckstatsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        tracks_in: the input track file.
        output: output only the field specified. Multiple such options can be\
            supplied if required. Choices are: mean, median, std, min, max, count.\
            Useful for use in scripts.
        histogram: output a histogram of streamline lengths.
        dump: dump the streamlines lengths to a text file.
        ignorezero: do not generate a warning if the track file contains\
            streamlines with zero length.
        tck_weights_in: specify a text scalar file containing the streamline\
            weights.
        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/tckstats",
        "ignorezero": ignorezero,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "tracks_in": tracks_in,
    }
    if output is not None:
        params["output"] = output
    if histogram is not None:
        params["histogram"] = histogram
    if dump is not None:
        params["dump"] = dump
    if tck_weights_in is not None:
        params["tck_weights_in"] = tck_weights_in
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def tckstats_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `TckstatsParamsDict` 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("output", None) is not None:
        if not isinstance(params["output"], list):
            raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `list[TckstatsOutputParamsDict] | None`')
        for e in params["output"]:
            tckstats_output_validate(e)
    if params.get("histogram", None) is not None:
        if not isinstance(params["histogram"], str):
            raise StyxValidationError(f'`histogram` has the wrong type: Received `{type(params.get("histogram", None))}` expected `str | None`')
    if params.get("dump", None) is not None:
        if not isinstance(params["dump"], str):
            raise StyxValidationError(f'`dump` has the wrong type: Received `{type(params.get("dump", None))}` expected `str | None`')
    if params.get("ignorezero", False) is None:
        raise StyxValidationError("`ignorezero` must not be None")
    if not isinstance(params["ignorezero"], bool):
        raise StyxValidationError(f'`ignorezero` has the wrong type: Received `{type(params.get("ignorezero", False))}` expected `bool`')
    if params.get("tck_weights_in", None) is not None:
        if not isinstance(params["tck_weights_in"], (pathlib.Path, str)):
            raise StyxValidationError(f'`tck_weights_in` has the wrong type: Received `{type(params.get("tck_weights_in", 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[TckstatsConfigParamsDict] | None`')
        for e in params["config"]:
            tckstats_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("tracks_in", None) is None:
        raise StyxValidationError("`tracks_in` must not be None")
    if not isinstance(params["tracks_in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`tracks_in` has the wrong type: Received `{type(params.get("tracks_in", None))}` expected `InputPathType`')


def tckstats_cargs(
    params: TckstatsParamsDict,
    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("tckstats")
    if params.get("output", None) is not None:
        cargs.extend([a for c in [tckstats_output_cargs(s, execution) for s in params.get("output", None)] for a in c])
    if params.get("histogram", None) is not None:
        cargs.extend([
            "-histogram",
            params.get("histogram", None)
        ])
    if params.get("dump", None) is not None:
        cargs.extend([
            "-dump",
            params.get("dump", None)
        ])
    if params.get("ignorezero", False):
        cargs.append("-ignorezero")
    if params.get("tck_weights_in", None) is not None:
        cargs.extend([
            "-tck_weights_in",
            execution.input_file(params.get("tck_weights_in", 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 [tckstats_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("tracks_in", None)))
    return cargs


def tckstats_outputs(
    params: TckstatsParamsDict,
    execution: Execution,
) -> TckstatsOutputs:
    """
    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 = TckstatsOutputs(
        root=execution.output_file("."),
        histogram=execution.output_file(params.get("histogram", None)) if (params.get("histogram") is not None) else None,
        dump=execution.output_file(params.get("dump", None)) if (params.get("dump") is not None) else None,
    )
    return ret


def tckstats_execute(
    params: TckstatsParamsDict,
    runner: Runner | None = None,
) -> TckstatsOutputs:
    """
    tckstats
    
    Calculate statistics on streamlines lengths.
    
    
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `TckstatsOutputs`).
    """
    tckstats_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(TCKSTATS_METADATA)
    params = execution.params(params)
    cargs = tckstats_cargs(params, execution)
    ret = tckstats_outputs(params, execution)
    execution.run(cargs)
    return ret


def tckstats(
    tracks_in: InputPathType,
    output: list[TckstatsOutputParamsDict] | None = None,
    histogram: str | None = None,
    dump: str | None = None,
    ignorezero: bool = False,
    tck_weights_in: InputPathType | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[TckstatsConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> TckstatsOutputs:
    """
    tckstats
    
    Calculate statistics on streamlines lengths.
    
    
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        tracks_in: the input track file.
        output: output only the field specified. Multiple such options can be\
            supplied if required. Choices are: mean, median, std, min, max, count.\
            Useful for use in scripts.
        histogram: output a histogram of streamline lengths.
        dump: dump the streamlines lengths to a text file.
        ignorezero: do not generate a warning if the track file contains\
            streamlines with zero length.
        tck_weights_in: specify a text scalar file containing the streamline\
            weights.
        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 `TckstatsOutputs`).
    """
    params = tckstats_params(
        output=output,
        histogram=histogram,
        dump=dump,
        ignorezero=ignorezero,
        tck_weights_in=tck_weights_in,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        tracks_in=tracks_in,
    )
    return tckstats_execute(params, runner)


__all__ = [
    "TCKSTATS_METADATA",
    "TckstatsConfigParamsDict",
    "TckstatsConfigParamsDictTagged",
    "TckstatsOutputParamsDict",
    "TckstatsOutputParamsDictTagged",
    "TckstatsOutputs",
    "TckstatsParamsDict",
    "TckstatsParamsDictTagged",
    "tckstats",
    "tckstats_config",
    "tckstats_execute",
    "tckstats_output",
    "tckstats_params",
]
