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

import typing
import pathlib
from styxdefs import *

V_5TTGEN_METADATA = Metadata(
    id="213c8cb30d8d1a68c488abbf08a42cf6809dc622.boutiques",
    name="5ttgen",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_V5ttgenFreesurferParamsDictNoTag = typing.TypedDict('_V5ttgenFreesurferParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
    "lut": typing.NotRequired[InputPathType | None],
})
V5ttgenFreesurferParamsDictTagged = typing.TypedDict('V5ttgenFreesurferParamsDictTagged', {
    "@type": typing.Literal["freesurfer"],
    "input": InputPathType,
    "output": str,
    "lut": typing.NotRequired[InputPathType | None],
})
V5ttgenFreesurferParamsDict = _V5ttgenFreesurferParamsDictNoTag | V5ttgenFreesurferParamsDictTagged


_V5ttgenFslParamsDictNoTag = typing.TypedDict('_V5ttgenFslParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
    "t2": typing.NotRequired[InputPathType | None],
    "mask": typing.NotRequired[InputPathType | None],
    "premasked": bool,
})
V5ttgenFslParamsDictTagged = typing.TypedDict('V5ttgenFslParamsDictTagged', {
    "@type": typing.Literal["fsl"],
    "input": InputPathType,
    "output": str,
    "t2": typing.NotRequired[InputPathType | None],
    "mask": typing.NotRequired[InputPathType | None],
    "premasked": bool,
})
V5ttgenFslParamsDict = _V5ttgenFslParamsDictNoTag | V5ttgenFslParamsDictTagged


_V5ttgenGifParamsDictNoTag = typing.TypedDict('_V5ttgenGifParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
})
V5ttgenGifParamsDictTagged = typing.TypedDict('V5ttgenGifParamsDictTagged', {
    "@type": typing.Literal["gif"],
    "input": InputPathType,
    "output": str,
})
V5ttgenGifParamsDict = _V5ttgenGifParamsDictNoTag | V5ttgenGifParamsDictTagged


_V5ttgenHsvsParamsDictNoTag = typing.TypedDict('_V5ttgenHsvsParamsDictNoTag', {
    "input": InputPathType,
    "output": str,
    "template": typing.NotRequired[InputPathType | None],
    "hippocampi": typing.NotRequired[typing.Literal["subfields", "first", "aseg"] | None],
    "thalami": typing.NotRequired[typing.Literal["nuclei", "first", "aseg"] | None],
    "white_stem": bool,
})
V5ttgenHsvsParamsDictTagged = typing.TypedDict('V5ttgenHsvsParamsDictTagged', {
    "@type": typing.Literal["hsvs"],
    "input": InputPathType,
    "output": str,
    "template": typing.NotRequired[InputPathType | None],
    "hippocampi": typing.NotRequired[typing.Literal["subfields", "first", "aseg"] | None],
    "thalami": typing.NotRequired[typing.Literal["nuclei", "first", "aseg"] | None],
    "white_stem": bool,
})
V5ttgenHsvsParamsDict = _V5ttgenHsvsParamsDictNoTag | V5ttgenHsvsParamsDictTagged


_V5ttgenConfigParamsDictNoTag = typing.TypedDict('_V5ttgenConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
V5ttgenConfigParamsDictTagged = typing.TypedDict('V5ttgenConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
V5ttgenConfigParamsDict = _V5ttgenConfigParamsDictNoTag | V5ttgenConfigParamsDictTagged


_V5ttgenParamsDictNoTag = typing.TypedDict('_V5ttgenParamsDictNoTag', {
    "algorithm": typing.Union[V5ttgenFreesurferParamsDictTagged, V5ttgenFslParamsDictTagged, V5ttgenGifParamsDictTagged, V5ttgenHsvsParamsDictTagged],
    "nocrop": bool,
    "sgm_amyg_hipp": bool,
    "nocleanup": bool,
    "scratch": typing.NotRequired[str | None],
    "continue": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[V5ttgenConfigParamsDict] | None],
    "help": bool,
    "version": bool,
})
V5ttgenParamsDictTagged = typing.TypedDict('V5ttgenParamsDictTagged', {
    "@type": typing.Literal["mrtrix/5ttgen"],
    "algorithm": typing.Union[V5ttgenFreesurferParamsDictTagged, V5ttgenFslParamsDictTagged, V5ttgenGifParamsDictTagged, V5ttgenHsvsParamsDictTagged],
    "nocrop": bool,
    "sgm_amyg_hipp": bool,
    "nocleanup": bool,
    "scratch": typing.NotRequired[str | None],
    "continue": typing.NotRequired[str | None],
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[V5ttgenConfigParamsDict] | None],
    "help": bool,
    "version": bool,
})
V5ttgenParamsDict = _V5ttgenParamsDictNoTag | V5ttgenParamsDictTagged


def v_5ttgen_algorithm_cargs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build cargs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build cargs function.
    """
    return {
        "freesurfer": v_5ttgen_freesurfer_cargs,
        "fsl": v_5ttgen_fsl_cargs,
        "gif": v_5ttgen_gif_cargs,
        "hsvs": v_5ttgen_hsvs_cargs,
    }.get(t)


def v_5ttgen_algorithm_outputs_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get build outputs function by command type.
    
    Args:
        t: Command type.
    Returns:
        Build outputs function.
    """
    return {
        "freesurfer": v_5ttgen_freesurfer_outputs,
        "fsl": v_5ttgen_fsl_outputs,
        "gif": v_5ttgen_gif_outputs,
        "hsvs": v_5ttgen_hsvs_outputs,
    }.get(t)


def v_5ttgen_algorithm_validate_dyn_fn(
    t: str,
) -> typing.Any:
    """
    Get validate params function by command type.
    
    Args:
        t: Command type.
    Returns:
        Validate params function.
    """
    return {
        "freesurfer": v_5ttgen_freesurfer_validate,
        "fsl": v_5ttgen_fsl_validate,
        "gif": v_5ttgen_gif_validate,
        "hsvs": v_5ttgen_hsvs_validate,
    }.get(t)


class V5ttgenFreesurferOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenFreesurferParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


def v_5ttgen_freesurfer(
    input_: InputPathType,
    output: str,
    lut: InputPathType | None = None,
) -> V5ttgenFreesurferParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input FreeSurfer parcellation image (any image containing\
            'aseg' in its name).
        output: The output 5TT image.
        lut: Manually provide path to the lookup table on which the input\
            parcellation image is based (e.g. FreeSurferColorLUT.txt).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "freesurfer",
        "input": input_,
        "output": output,
    }
    if lut is not None:
        params["lut"] = lut
    return params


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


def v_5ttgen_freesurfer_cargs(
    params: V5ttgenFreesurferParamsDict,
    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("freesurfer")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    if params.get("lut", None) is not None:
        cargs.extend([
            "-lut",
            execution.input_file(params.get("lut", None))
        ])
    return cargs


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


class V5ttgenFslOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenFslParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


def v_5ttgen_fsl(
    input_: InputPathType,
    output: str,
    t2: InputPathType | None = None,
    mask: InputPathType | None = None,
    premasked: bool = False,
) -> V5ttgenFslParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input T1-weighted image.
        output: The output 5TT image.
        t2: Provide a T2-weighted image in addition to the default T1-weighted\
            image; this will be used as a second input to FSL FAST.
        mask: Manually provide a brain mask, rather than deriving one in the\
            script.
        premasked: Indicate that brain masking has already been applied to the\
            input image.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "fsl",
        "input": input_,
        "output": output,
        "premasked": premasked,
    }
    if t2 is not None:
        params["t2"] = t2
    if mask is not None:
        params["mask"] = mask
    return params


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


def v_5ttgen_fsl_cargs(
    params: V5ttgenFslParamsDict,
    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("fsl")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    if params.get("t2", None) is not None:
        cargs.extend([
            "-t2",
            execution.input_file(params.get("t2", None))
        ])
    if params.get("mask", None) is not None:
        cargs.extend([
            "-mask",
            execution.input_file(params.get("mask", None))
        ])
    if params.get("premasked", False):
        cargs.append("-premasked")
    return cargs


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


class V5ttgenGifOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenGifParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


def v_5ttgen_gif(
    input_: InputPathType,
    output: str,
) -> V5ttgenGifParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input Geodesic Information Flow (GIF) segmentation image.
        output: The output 5TT image.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "gif",
        "input": input_,
        "output": output,
    }
    return params


def v_5ttgen_gif_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `V5ttgenGifParamsDict` 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", 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("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 v_5ttgen_gif_cargs(
    params: V5ttgenGifParamsDict,
    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("gif")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    return cargs


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


class V5ttgenHsvsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenHsvsParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """The output 5TT image"""


def v_5ttgen_hsvs(
    input_: InputPathType,
    output: str,
    template: InputPathType | None = None,
    hippocampi: typing.Literal["subfields", "first", "aseg"] | None = None,
    thalami: typing.Literal["nuclei", "first", "aseg"] | None = None,
    white_stem: bool = False,
) -> V5ttgenHsvsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: The input FreeSurfer subject directory.
        output: The output 5TT image.
        template: Provide an image that will form the template for the\
            generated 5TT image.
        hippocampi: Select method to be used for hippocampi (& amygdalae)\
            segmentation; options are: subfields,first,aseg.
        thalami: Select method to be used for thalamic segmentation; options\
            are: nuclei,first,aseg.
        white_stem: Classify the brainstem as white matter.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "hsvs",
        "input": input_,
        "output": output,
        "white_stem": white_stem,
    }
    if template is not None:
        params["template"] = template
    if hippocampi is not None:
        params["hippocampi"] = hippocampi
    if thalami is not None:
        params["thalami"] = thalami
    return params


def v_5ttgen_hsvs_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `V5ttgenHsvsParamsDict` 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", 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("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`')
    if params.get("template", None) is not None:
        if not isinstance(params["template"], (pathlib.Path, str)):
            raise StyxValidationError(f'`template` has the wrong type: Received `{type(params.get("template", None))}` expected `InputPathType | None`')
    if params.get("hippocampi", None) is not None:
        if not isinstance(params["hippocampi"], str):
            raise StyxValidationError(f'`hippocampi` has the wrong type: Received `{type(params.get("hippocampi", None))}` expected `typing.Literal["subfields", "first", "aseg"] | None`')
        if params["hippocampi"] not in ["subfields", "first", "aseg"]:
            raise StyxValidationError("Parameter `hippocampi` must be one of [\"subfields\", \"first\", \"aseg\"]")
    if params.get("thalami", None) is not None:
        if not isinstance(params["thalami"], str):
            raise StyxValidationError(f'`thalami` has the wrong type: Received `{type(params.get("thalami", None))}` expected `typing.Literal["nuclei", "first", "aseg"] | None`')
        if params["thalami"] not in ["nuclei", "first", "aseg"]:
            raise StyxValidationError("Parameter `thalami` must be one of [\"nuclei\", \"first\", \"aseg\"]")
    if params.get("white_stem", False) is None:
        raise StyxValidationError("`white_stem` must not be None")
    if not isinstance(params["white_stem"], bool):
        raise StyxValidationError(f'`white_stem` has the wrong type: Received `{type(params.get("white_stem", False))}` expected `bool`')


def v_5ttgen_hsvs_cargs(
    params: V5ttgenHsvsParamsDict,
    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("hsvs")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("output", None))
    if params.get("template", None) is not None:
        cargs.extend([
            "-template",
            execution.input_file(params.get("template", None))
        ])
    if params.get("hippocampi", None) is not None:
        cargs.extend([
            "-hippocampi",
            params.get("hippocampi", None)
        ])
    if params.get("thalami", None) is not None:
        cargs.extend([
            "-thalami",
            params.get("thalami", None)
        ])
    if params.get("white_stem", False):
        cargs.append("-white_stem")
    return cargs


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


def v_5ttgen_config(
    key: str,
    value: str,
) -> V5ttgenConfigParamsDictTagged:
    """
    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 v_5ttgen_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `V5ttgenConfigParamsDict` 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 v_5ttgen_config_cargs(
    params: V5ttgenConfigParamsDict,
    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 V5ttgenOutputs(typing.NamedTuple):
    """
    Output object returned when calling `V5ttgenParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    algorithm: typing.Union[V5ttgenFreesurferOutputs, V5ttgenFslOutputs, V5ttgenGifOutputs, V5ttgenHsvsOutputs]
    """Outputs from `V5ttgenFreesurferParamsDict` or `V5ttgenFslParamsDict` or
    `V5ttgenGifParamsDict` or `V5ttgenHsvsParamsDict`."""


def v_5ttgen_params(
    algorithm: typing.Union[V5ttgenFreesurferParamsDictTagged, V5ttgenFslParamsDictTagged, V5ttgenGifParamsDictTagged, V5ttgenHsvsParamsDictTagged],
    nocrop: bool = False,
    sgm_amyg_hipp: bool = False,
    nocleanup: bool = False,
    scratch: str | None = None,
    continue_: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[V5ttgenConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
) -> V5ttgenParamsDictTagged:
    """
    Build parameters.
    
    Args:
        algorithm: Select the algorithm to be used to complete the script\
            operation; additional details and options become available once an\
            algorithm is nominated. Options are: freesurfer, fsl, gif, hsvs.
        nocrop: Do NOT crop the resulting 5TT image to reduce its size (keep\
            the same dimensions as the input image).
        sgm_amyg_hipp: Represent the amygdalae and hippocampi as sub-cortical\
            grey matter in the 5TT image.
        nocleanup: do not delete intermediate files during script execution,\
            and do not delete scratch directory at script completion.
        scratch: manually specify the path in which to generate the scratch\
            directory.
        continue_: continue the script from a previous execution; must provide\
            the scratch directory path, and the name of the last\
            successfully-generated file.
        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/5ttgen",
        "algorithm": algorithm,
        "nocrop": nocrop,
        "sgm_amyg_hipp": sgm_amyg_hipp,
        "nocleanup": nocleanup,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
    }
    if scratch is not None:
        params["scratch"] = scratch
    if continue_ is not None:
        params["continue"] = continue_
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    return params


def v_5ttgen_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `V5ttgenParamsDict` 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("algorithm", None) is None:
        raise StyxValidationError("`algorithm` must not be None")
    if not isinstance(params["algorithm"], dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params["algorithm"])}\'')
    if "@type" not in params["algorithm"]:
        raise StyxValidationError("Params object is missing `@type`")
    if params["algorithm"]["@type"] not in ["freesurfer", "fsl", "gif", "hsvs"]:
        raise StyxValidationError("Parameter `algorithm`s `@type` must be one of [\"freesurfer\", \"fsl\", \"gif\", \"hsvs\"]")
    v_5ttgen_algorithm_validate_dyn_fn(params["algorithm"]["@type"])(params["algorithm"])
    if params.get("nocrop", False) is None:
        raise StyxValidationError("`nocrop` must not be None")
    if not isinstance(params["nocrop"], bool):
        raise StyxValidationError(f'`nocrop` has the wrong type: Received `{type(params.get("nocrop", False))}` expected `bool`')
    if params.get("sgm_amyg_hipp", False) is None:
        raise StyxValidationError("`sgm_amyg_hipp` must not be None")
    if not isinstance(params["sgm_amyg_hipp"], bool):
        raise StyxValidationError(f'`sgm_amyg_hipp` has the wrong type: Received `{type(params.get("sgm_amyg_hipp", 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", None) is not None:
        if not isinstance(params["scratch"], str):
            raise StyxValidationError(f'`scratch` has the wrong type: Received `{type(params.get("scratch", None))}` expected `str | None`')
    if params.get("continue", None) is not None:
        if not isinstance(params["continue"], str):
            raise StyxValidationError(f'`continue` has the wrong type: Received `{type(params.get("continue", None))}` expected `str | 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[V5ttgenConfigParamsDict] | None`')
        for e in params["config"]:
            v_5ttgen_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`')


def v_5ttgen_cargs(
    params: V5ttgenParamsDict,
    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("5ttgen")
    cargs.extend(v_5ttgen_algorithm_cargs_dyn_fn(params.get("algorithm", None)["@type"])(params.get("algorithm", None), execution))
    if params.get("nocrop", False):
        cargs.append("-nocrop")
    if params.get("sgm_amyg_hipp", False):
        cargs.append("-sgm_amyg_hipp")
    if params.get("nocleanup", False):
        cargs.append("-nocleanup")
    if params.get("scratch", None) is not None:
        cargs.extend([
            "-scratch",
            params.get("scratch", None)
        ])
    if params.get("continue", None) is not None:
        cargs.extend([
            "-continue",
            params.get("continue", 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 [v_5ttgen_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")
    return cargs


def v_5ttgen_outputs(
    params: V5ttgenParamsDict,
    execution: Execution,
) -> V5ttgenOutputs:
    """
    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 = V5ttgenOutputs(
        root=execution.output_file("."),
        algorithm=v_5ttgen_algorithm_outputs_dyn_fn(params.get("algorithm")["@type"])(params.get("algorithm"), execution),
    )
    return ret


def v_5ttgen_execute(
    params: V5ttgenParamsDict,
    runner: Runner | None = None,
) -> V5ttgenOutputs:
    """
    5ttgen
    
    Generate a 5TT image suitable for ACT.
    
    5ttgen acts as a 'master' script for generating a five-tissue-type (5TT)
    segmented tissue image suitable for use in Anatomically-Constrained
    Tractography (ACT). A range of different algorithms are available for
    completing this task. When using this script, the name of the algorithm to
    be used must appear as the first argument on the command-line after
    '5ttgen'. The subsequent compulsory arguments and options available depend
    on the particular algorithm being invoked.
    Each algorithm available also has its own help page, including necessary
    references; e.g. to see the help page of the 'fsl' algorithm, type '5ttgen
    fsl'.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V5ttgenOutputs`).
    """
    v_5ttgen_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_5TTGEN_METADATA)
    params = execution.params(params)
    cargs = v_5ttgen_cargs(params, execution)
    ret = v_5ttgen_outputs(params, execution)
    execution.run(cargs)
    return ret


def v_5ttgen(
    algorithm: typing.Union[V5ttgenFreesurferParamsDictTagged, V5ttgenFslParamsDictTagged, V5ttgenGifParamsDictTagged, V5ttgenHsvsParamsDictTagged],
    nocrop: bool = False,
    sgm_amyg_hipp: bool = False,
    nocleanup: bool = False,
    scratch: str | None = None,
    continue_: str | None = None,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[V5ttgenConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> V5ttgenOutputs:
    """
    5ttgen
    
    Generate a 5TT image suitable for ACT.
    
    5ttgen acts as a 'master' script for generating a five-tissue-type (5TT)
    segmented tissue image suitable for use in Anatomically-Constrained
    Tractography (ACT). A range of different algorithms are available for
    completing this task. When using this script, the name of the algorithm to
    be used must appear as the first argument on the command-line after
    '5ttgen'. The subsequent compulsory arguments and options available depend
    on the particular algorithm being invoked.
    Each algorithm available also has its own help page, including necessary
    references; e.g. to see the help page of the 'fsl' algorithm, type '5ttgen
    fsl'.
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        algorithm: Select the algorithm to be used to complete the script\
            operation; additional details and options become available once an\
            algorithm is nominated. Options are: freesurfer, fsl, gif, hsvs.
        nocrop: Do NOT crop the resulting 5TT image to reduce its size (keep\
            the same dimensions as the input image).
        sgm_amyg_hipp: Represent the amygdalae and hippocampi as sub-cortical\
            grey matter in the 5TT image.
        nocleanup: do not delete intermediate files during script execution,\
            and do not delete scratch directory at script completion.
        scratch: manually specify the path in which to generate the scratch\
            directory.
        continue_: continue the script from a previous execution; must provide\
            the scratch directory path, and the name of the last\
            successfully-generated file.
        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 `V5ttgenOutputs`).
    """
    params = v_5ttgen_params(
        algorithm=algorithm,
        nocrop=nocrop,
        sgm_amyg_hipp=sgm_amyg_hipp,
        nocleanup=nocleanup,
        scratch=scratch,
        continue_=continue_,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
    )
    return v_5ttgen_execute(params, runner)


__all__ = [
    "V5ttgenConfigParamsDict",
    "V5ttgenConfigParamsDictTagged",
    "V5ttgenFreesurferOutputs",
    "V5ttgenFreesurferParamsDict",
    "V5ttgenFreesurferParamsDictTagged",
    "V5ttgenFslOutputs",
    "V5ttgenFslParamsDict",
    "V5ttgenFslParamsDictTagged",
    "V5ttgenGifOutputs",
    "V5ttgenGifParamsDict",
    "V5ttgenGifParamsDictTagged",
    "V5ttgenHsvsOutputs",
    "V5ttgenHsvsParamsDict",
    "V5ttgenHsvsParamsDictTagged",
    "V5ttgenOutputs",
    "V5ttgenParamsDict",
    "V5ttgenParamsDictTagged",
    "V_5TTGEN_METADATA",
    "v_5ttgen",
    "v_5ttgen_config",
    "v_5ttgen_execute",
    "v_5ttgen_freesurfer",
    "v_5ttgen_fsl",
    "v_5ttgen_gif",
    "v_5ttgen_hsvs",
    "v_5ttgen_params",
]
