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

import typing
import pathlib
from styxdefs import *

FIXELCORRESPONDENCE_METADATA = Metadata(
    id="0cdb6d5a0f6fc504a73335d26a91aed6bead44ba.boutiques",
    name="fixelcorrespondence",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_FixelcorrespondenceConfigParamsDictNoTag = typing.TypedDict('_FixelcorrespondenceConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
FixelcorrespondenceConfigParamsDictTagged = typing.TypedDict('FixelcorrespondenceConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
FixelcorrespondenceConfigParamsDict = _FixelcorrespondenceConfigParamsDictNoTag | FixelcorrespondenceConfigParamsDictTagged


_FixelcorrespondenceParamsDictNoTag = typing.TypedDict('_FixelcorrespondenceParamsDictNoTag', {
    "angle": typing.NotRequired[float | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[FixelcorrespondenceConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "subject_data": InputPathType,
    "template_directory": InputPathType,
    "output_directory": str,
    "output_data": str,
})
FixelcorrespondenceParamsDictTagged = typing.TypedDict('FixelcorrespondenceParamsDictTagged', {
    "@type": typing.Literal["mrtrix/fixelcorrespondence"],
    "angle": typing.NotRequired[float | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[FixelcorrespondenceConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "subject_data": InputPathType,
    "template_directory": InputPathType,
    "output_directory": str,
    "output_data": str,
})
FixelcorrespondenceParamsDict = _FixelcorrespondenceParamsDictNoTag | FixelcorrespondenceParamsDictTagged


def fixelcorrespondence_config(
    key: str,
    value: str,
) -> FixelcorrespondenceConfigParamsDictTagged:
    """
    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 fixelcorrespondence_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FixelcorrespondenceConfigParamsDict` 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 fixelcorrespondence_config_cargs(
    params: FixelcorrespondenceConfigParamsDict,
    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 FixelcorrespondenceOutputs(typing.NamedTuple):
    """
    Output object returned when calling `FixelcorrespondenceParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def fixelcorrespondence_params(
    subject_data: InputPathType,
    template_directory: InputPathType,
    output_directory: str,
    output_data: str,
    angle: float | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[FixelcorrespondenceConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> FixelcorrespondenceParamsDictTagged:
    """
    Build parameters.
    
    Args:
        subject_data: the input subject fixel data file. This should be a file\
            inside the fixel directory.
        template_directory: the input template fixel directory.
        output_directory: the fixel directory where the output file will be\
            written.
        output_data: the name of the output fixel data file. This will be\
            placed in the output fixel directory.
        angle: the max angle threshold for computing inter-subject fixel\
            correspondence (Default: 45 degrees).
        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/fixelcorrespondence",
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "subject_data": subject_data,
        "template_directory": template_directory,
        "output_directory": output_directory,
        "output_data": output_data,
    }
    if angle is not None:
        params["angle"] = angle
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def fixelcorrespondence_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `FixelcorrespondenceParamsDict` 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("angle", None) is not None:
        if not isinstance(params["angle"], (float, int)):
            raise StyxValidationError(f'`angle` has the wrong type: Received `{type(params.get("angle", None))}` expected `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[FixelcorrespondenceConfigParamsDict] | None`')
        for e in params["config"]:
            fixelcorrespondence_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("subject_data", None) is None:
        raise StyxValidationError("`subject_data` must not be None")
    if not isinstance(params["subject_data"], (pathlib.Path, str)):
        raise StyxValidationError(f'`subject_data` has the wrong type: Received `{type(params.get("subject_data", None))}` expected `InputPathType`')
    if params.get("template_directory", None) is None:
        raise StyxValidationError("`template_directory` must not be None")
    if not isinstance(params["template_directory"], (pathlib.Path, str)):
        raise StyxValidationError(f'`template_directory` has the wrong type: Received `{type(params.get("template_directory", None))}` expected `InputPathType`')
    if params.get("output_directory", None) is None:
        raise StyxValidationError("`output_directory` must not be None")
    if not isinstance(params["output_directory"], str):
        raise StyxValidationError(f'`output_directory` has the wrong type: Received `{type(params.get("output_directory", None))}` expected `str`')
    if params.get("output_data", None) is None:
        raise StyxValidationError("`output_data` must not be None")
    if not isinstance(params["output_data"], str):
        raise StyxValidationError(f'`output_data` has the wrong type: Received `{type(params.get("output_data", None))}` expected `str`')


def fixelcorrespondence_cargs(
    params: FixelcorrespondenceParamsDict,
    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("fixelcorrespondence")
    if params.get("angle", None) is not None:
        cargs.extend([
            "-angle",
            str(params.get("angle", 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 [fixelcorrespondence_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("subject_data", None)))
    cargs.append(execution.input_file(params.get("template_directory", None)))
    cargs.append(params.get("output_directory", None))
    cargs.append(params.get("output_data", None))
    return cargs


def fixelcorrespondence_outputs(
    params: FixelcorrespondenceParamsDict,
    execution: Execution,
) -> FixelcorrespondenceOutputs:
    """
    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 = FixelcorrespondenceOutputs(
        root=execution.output_file("."),
    )
    return ret


def fixelcorrespondence_execute(
    params: FixelcorrespondenceParamsDict,
    runner: Runner | None = None,
) -> FixelcorrespondenceOutputs:
    """
    fixelcorrespondence
    
    Obtain fixel-fixel correpondence between a subject fixel image and a
    template fixel mask.
    
    It is assumed that the subject image has already been spatially normalised
    and is aligned with the template. The output fixel image will have the same
    fixels (and directions) of the template.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `FixelcorrespondenceOutputs`).
    """
    fixelcorrespondence_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(FIXELCORRESPONDENCE_METADATA)
    params = execution.params(params)
    cargs = fixelcorrespondence_cargs(params, execution)
    ret = fixelcorrespondence_outputs(params, execution)
    execution.run(cargs)
    return ret


def fixelcorrespondence(
    subject_data: InputPathType,
    template_directory: InputPathType,
    output_directory: str,
    output_data: str,
    angle: float | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[FixelcorrespondenceConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> FixelcorrespondenceOutputs:
    """
    fixelcorrespondence
    
    Obtain fixel-fixel correpondence between a subject fixel image and a
    template fixel mask.
    
    It is assumed that the subject image has already been spatially normalised
    and is aligned with the template. The output fixel image will have the same
    fixels (and directions) of the template.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        subject_data: the input subject fixel data file. This should be a file\
            inside the fixel directory.
        template_directory: the input template fixel directory.
        output_directory: the fixel directory where the output file will be\
            written.
        output_data: the name of the output fixel data file. This will be\
            placed in the output fixel directory.
        angle: the max angle threshold for computing inter-subject fixel\
            correspondence (Default: 45 degrees).
        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 `FixelcorrespondenceOutputs`).
    """
    params = fixelcorrespondence_params(
        angle=angle,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        subject_data=subject_data,
        template_directory=template_directory,
        output_directory=output_directory,
        output_data=output_data,
    )
    return fixelcorrespondence_execute(params, runner)


__all__ = [
    "FIXELCORRESPONDENCE_METADATA",
    "FixelcorrespondenceConfigParamsDict",
    "FixelcorrespondenceConfigParamsDictTagged",
    "FixelcorrespondenceOutputs",
    "FixelcorrespondenceParamsDict",
    "FixelcorrespondenceParamsDictTagged",
    "fixelcorrespondence",
    "fixelcorrespondence_config",
    "fixelcorrespondence_execute",
    "fixelcorrespondence_params",
]
