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

import typing
import pathlib
from styxdefs import *

RESPONSEMEAN_METADATA = Metadata(
    id="580e677d66de76d497b1d37c93d76dd82a169d45.boutiques",
    name="responsemean",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_ResponsemeanParamsDictNoTag = typing.TypedDict('_ResponsemeanParamsDictNoTag', {
    "input_response": list[InputPathType],
    "output_response": str,
    "legacy": bool,
    "nocleanup": bool,
    "scratch_dir": typing.NotRequired[InputPathType | None],
    "continue_scratch_dir": typing.NotRequired[list[InputPathType] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[float | None],
    "config": typing.NotRequired[list[str] | None],
    "help": bool,
    "version": bool,
})
ResponsemeanParamsDictTagged = typing.TypedDict('ResponsemeanParamsDictTagged', {
    "@type": typing.Literal["mrtrix/responsemean"],
    "input_response": list[InputPathType],
    "output_response": str,
    "legacy": bool,
    "nocleanup": bool,
    "scratch_dir": typing.NotRequired[InputPathType | None],
    "continue_scratch_dir": typing.NotRequired[list[InputPathType] | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[float | None],
    "config": typing.NotRequired[list[str] | None],
    "help": bool,
    "version": bool,
})
ResponsemeanParamsDict = _ResponsemeanParamsDictNoTag | ResponsemeanParamsDictTagged


class ResponsemeanOutputs(typing.NamedTuple):
    """
    Output object returned when calling `ResponsemeanParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_response_file: OutputPathType
    """File containing the averaged tissue response function"""


def responsemean_params(
    input_response: list[InputPathType],
    output_response: str,
    legacy: bool = False,
    nocleanup: bool = False,
    scratch_dir: InputPathType | None = None,
    continue_scratch_dir: list[InputPathType] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: float | None = None,
    config: list[str] | None = None,
    help_: bool = False,
    version: bool = False,
) -> ResponsemeanParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_response: Input response functions.
        output_response: Output mean response function.
        legacy: Calculate the mean response function from a set of text files.
        nocleanup: Do not delete intermediate files during script execution,\
            and do not delete scratch directory at script completion.
        scratch_dir: Manually specify the path in which to generate the scratch\
            directory.
        continue_scratch_dir: Continue the script from a previous execution;\
            must provide the scratch directory path.
        info: Display information messages.
        quiet: Do not display information messages or progress status.
        debug: Display debugging messages.
        force: Force overwrite of output files.
        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 help information and exit.
        version: Display version information and exit.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mrtrix/responsemean",
        "input_response": input_response,
        "output_response": output_response,
        "legacy": legacy,
        "nocleanup": nocleanup,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
    }
    if scratch_dir is not None:
        params["scratch_dir"] = scratch_dir
    if continue_scratch_dir is not None:
        params["continue_scratch_dir"] = continue_scratch_dir
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def responsemean_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ResponsemeanParamsDict` 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("input_response", None) is None:
        raise StyxValidationError("`input_response` must not be None")
    if not isinstance(params["input_response"], list):
        raise StyxValidationError(f'`input_response` has the wrong type: Received `{type(params.get("input_response", None))}` expected `list[InputPathType]`')
    for e in params["input_response"]:
        if not isinstance(e, (pathlib.Path, str)):
            raise StyxValidationError(f'`input_response` has the wrong type: Received `{type(params.get("input_response", None))}` expected `list[InputPathType]`')
    if params.get("output_response", None) is None:
        raise StyxValidationError("`output_response` must not be None")
    if not isinstance(params["output_response"], str):
        raise StyxValidationError(f'`output_response` has the wrong type: Received `{type(params.get("output_response", None))}` expected `str`')
    if params.get("legacy", False) is None:
        raise StyxValidationError("`legacy` must not be None")
    if not isinstance(params["legacy"], bool):
        raise StyxValidationError(f'`legacy` has the wrong type: Received `{type(params.get("legacy", False))}` expected `bool`')
    if params.get("nocleanup", False) is None:
        raise StyxValidationError("`nocleanup` must not be None")
    if not isinstance(params["nocleanup"], bool):
        raise StyxValidationError(f'`nocleanup` has the wrong type: Received `{type(params.get("nocleanup", False))}` expected `bool`')
    if params.get("scratch_dir", None) is not None:
        if not isinstance(params["scratch_dir"], (pathlib.Path, str)):
            raise StyxValidationError(f'`scratch_dir` has the wrong type: Received `{type(params.get("scratch_dir", None))}` expected `InputPathType | None`')
    if params.get("continue_scratch_dir", None) is not None:
        if not isinstance(params["continue_scratch_dir"], list):
            raise StyxValidationError(f'`continue_scratch_dir` has the wrong type: Received `{type(params.get("continue_scratch_dir", None))}` expected `list[InputPathType] | None`')
        if len(params["continue_scratch_dir"]) != 2:
            raise StyxValidationError("Parameter `continue_scratch_dir` must contain exactly 2 elements")
        for e in params["continue_scratch_dir"]:
            if not isinstance(e, (pathlib.Path, str)):
                raise StyxValidationError(f'`continue_scratch_dir` has the wrong type: Received `{type(params.get("continue_scratch_dir", None))}` expected `list[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"], (float, int)):
            raise StyxValidationError(f'`nthreads` has the wrong type: Received `{type(params.get("nthreads", None))}` expected `float | 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[str] | None`')
        for e in params["config"]:
            if not isinstance(e, str):
                raise StyxValidationError(f'`config` has the wrong type: Received `{type(params.get("config", None))}` expected `list[str] | None`')
    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`')


def responsemean_cargs(
    params: ResponsemeanParamsDict,
    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("responsemean")
    cargs.extend([execution.input_file(f) for f in params.get("input_response", None)])
    cargs.append(params.get("output_response", None))
    if params.get("legacy", False):
        cargs.append("-legacy")
    if params.get("nocleanup", False):
        cargs.append("-nocleanup")
    if params.get("scratch_dir", None) is not None:
        cargs.extend([
            "-scratch",
            execution.input_file(params.get("scratch_dir", None))
        ])
    if params.get("continue_scratch_dir", None) is not None:
        cargs.extend([
            "-continue",
            *[execution.input_file(f) for f in params.get("continue_scratch_dir", 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([
            "-config",
            *params.get("config", None)
        ])
    if params.get("help", False):
        cargs.append("-help")
    if params.get("version", False):
        cargs.append("-version")
    return cargs


def responsemean_outputs(
    params: ResponsemeanParamsDict,
    execution: Execution,
) -> ResponsemeanOutputs:
    """
    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 = ResponsemeanOutputs(
        root=execution.output_file("."),
        output_response_file=execution.output_file(params.get("output_response", None)),
    )
    return ret


def responsemean_execute(
    params: ResponsemeanParamsDict,
    runner: Runner | None = None,
) -> ResponsemeanOutputs:
    """
    responsemean
    
    Calculate the mean response function from a set of text files.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ResponsemeanOutputs`).
    """
    responsemean_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(RESPONSEMEAN_METADATA)
    params = execution.params(params)
    cargs = responsemean_cargs(params, execution)
    ret = responsemean_outputs(params, execution)
    execution.run(cargs)
    return ret


def responsemean(
    input_response: list[InputPathType],
    output_response: str,
    legacy: bool = False,
    nocleanup: bool = False,
    scratch_dir: InputPathType | None = None,
    continue_scratch_dir: list[InputPathType] | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: float | None = None,
    config: list[str] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> ResponsemeanOutputs:
    """
    responsemean
    
    Calculate the mean response function from a set of text files.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        input_response: Input response functions.
        output_response: Output mean response function.
        legacy: Calculate the mean response function from a set of text files.
        nocleanup: Do not delete intermediate files during script execution,\
            and do not delete scratch directory at script completion.
        scratch_dir: Manually specify the path in which to generate the scratch\
            directory.
        continue_scratch_dir: Continue the script from a previous execution;\
            must provide the scratch directory path.
        info: Display information messages.
        quiet: Do not display information messages or progress status.
        debug: Display debugging messages.
        force: Force overwrite of output files.
        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 help information and exit.
        version: Display version information and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ResponsemeanOutputs`).
    """
    params = responsemean_params(
        input_response=input_response,
        output_response=output_response,
        legacy=legacy,
        nocleanup=nocleanup,
        scratch_dir=scratch_dir,
        continue_scratch_dir=continue_scratch_dir,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
    )
    return responsemean_execute(params, runner)


__all__ = [
    "RESPONSEMEAN_METADATA",
    "ResponsemeanOutputs",
    "ResponsemeanParamsDict",
    "ResponsemeanParamsDictTagged",
    "responsemean",
    "responsemean_execute",
    "responsemean_params",
]
