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

import typing
import pathlib
from styxdefs import *

MREDIT_METADATA = Metadata(
    id="678a737a8aca3b1d9299ee0e4e4b44fe21b937dd.boutiques",
    name="mredit",
    package="mrtrix",
    container_image_tag="mrtrix3/mrtrix3:3.0.4",
)


_MreditPlaneParamsDictNoTag = typing.TypedDict('_MreditPlaneParamsDictNoTag', {
    "axis": int,
    "coord": list[int],
    "value": float,
})
MreditPlaneParamsDictTagged = typing.TypedDict('MreditPlaneParamsDictTagged', {
    "@type": typing.Literal["plane"],
    "axis": int,
    "coord": list[int],
    "value": float,
})
MreditPlaneParamsDict = _MreditPlaneParamsDictNoTag | MreditPlaneParamsDictTagged


_MreditSphereParamsDictNoTag = typing.TypedDict('_MreditSphereParamsDictNoTag', {
    "position": list[float],
    "radius": float,
    "value": float,
})
MreditSphereParamsDictTagged = typing.TypedDict('MreditSphereParamsDictTagged', {
    "@type": typing.Literal["sphere"],
    "position": list[float],
    "radius": float,
    "value": float,
})
MreditSphereParamsDict = _MreditSphereParamsDictNoTag | MreditSphereParamsDictTagged


_MreditVoxelParamsDictNoTag = typing.TypedDict('_MreditVoxelParamsDictNoTag', {
    "position": list[float],
    "value": float,
})
MreditVoxelParamsDictTagged = typing.TypedDict('MreditVoxelParamsDictTagged', {
    "@type": typing.Literal["voxel"],
    "position": list[float],
    "value": float,
})
MreditVoxelParamsDict = _MreditVoxelParamsDictNoTag | MreditVoxelParamsDictTagged


_MreditConfigParamsDictNoTag = typing.TypedDict('_MreditConfigParamsDictNoTag', {
    "key": str,
    "value": str,
})
MreditConfigParamsDictTagged = typing.TypedDict('MreditConfigParamsDictTagged', {
    "@type": typing.Literal["config"],
    "key": str,
    "value": str,
})
MreditConfigParamsDict = _MreditConfigParamsDictNoTag | MreditConfigParamsDictTagged


_MreditParamsDictNoTag = typing.TypedDict('_MreditParamsDictNoTag', {
    "plane": typing.NotRequired[list[MreditPlaneParamsDict] | None],
    "sphere": typing.NotRequired[list[MreditSphereParamsDict] | None],
    "voxel": typing.NotRequired[list[MreditVoxelParamsDict] | None],
    "scanner": bool,
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MreditConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "output": typing.NotRequired[str | None],
})
MreditParamsDictTagged = typing.TypedDict('MreditParamsDictTagged', {
    "@type": typing.Literal["mrtrix/mredit"],
    "plane": typing.NotRequired[list[MreditPlaneParamsDict] | None],
    "sphere": typing.NotRequired[list[MreditSphereParamsDict] | None],
    "voxel": typing.NotRequired[list[MreditVoxelParamsDict] | None],
    "scanner": bool,
    "info": bool,
    "quiet": bool,
    "debug": bool,
    "force": bool,
    "nthreads": typing.NotRequired[int | None],
    "config": typing.NotRequired[list[MreditConfigParamsDict] | None],
    "help": bool,
    "version": bool,
    "input": InputPathType,
    "output": typing.NotRequired[str | None],
})
MreditParamsDict = _MreditParamsDictNoTag | MreditParamsDictTagged


def mredit_plane(
    axis: int,
    coord: list[int],
    value: float,
) -> MreditPlaneParamsDictTagged:
    """
    Build parameters.
    
    Args:
        axis: fill one or more planes on a particular image axis.
        coord: fill one or more planes on a particular image axis.
        value: fill one or more planes on a particular image axis.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "plane",
        "axis": axis,
        "coord": coord,
        "value": value,
    }
    return params


def mredit_plane_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MreditPlaneParamsDict` 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("axis", None) is None:
        raise StyxValidationError("`axis` must not be None")
    if not isinstance(params["axis"], int):
        raise StyxValidationError(f'`axis` has the wrong type: Received `{type(params.get("axis", None))}` expected `int`')
    if params.get("coord", None) is None:
        raise StyxValidationError("`coord` must not be None")
    if not isinstance(params["coord"], list):
        raise StyxValidationError(f'`coord` has the wrong type: Received `{type(params.get("coord", None))}` expected `list[int]`')
    for e in params["coord"]:
        if not isinstance(e, int):
            raise StyxValidationError(f'`coord` has the wrong type: Received `{type(params.get("coord", None))}` expected `list[int]`')
    if params.get("value", None) is None:
        raise StyxValidationError("`value` must not be None")
    if not isinstance(params["value"], (float, int)):
        raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `float`')


def mredit_plane_cargs(
    params: MreditPlaneParamsDict,
    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("-plane")
    cargs.append(str(params.get("axis", None)))
    cargs.extend(map(str, params.get("coord", None)))
    cargs.append(str(params.get("value", None)))
    return cargs


def mredit_sphere(
    position: list[float],
    radius: float,
    value: float,
) -> MreditSphereParamsDictTagged:
    """
    Build parameters.
    
    Args:
        position: draw a sphere with radius in mm.
        radius: draw a sphere with radius in mm.
        value: draw a sphere with radius in mm.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "sphere",
        "position": position,
        "radius": radius,
        "value": value,
    }
    return params


def mredit_sphere_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MreditSphereParamsDict` 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("position", None) is None:
        raise StyxValidationError("`position` must not be None")
    if not isinstance(params["position"], list):
        raise StyxValidationError(f'`position` has the wrong type: Received `{type(params.get("position", None))}` expected `list[float]`')
    for e in params["position"]:
        if not isinstance(e, (float, int)):
            raise StyxValidationError(f'`position` has the wrong type: Received `{type(params.get("position", None))}` expected `list[float]`')
    if params.get("radius", None) is None:
        raise StyxValidationError("`radius` must not be None")
    if not isinstance(params["radius"], (float, int)):
        raise StyxValidationError(f'`radius` has the wrong type: Received `{type(params.get("radius", None))}` expected `float`')
    if params.get("value", None) is None:
        raise StyxValidationError("`value` must not be None")
    if not isinstance(params["value"], (float, int)):
        raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `float`')


def mredit_sphere_cargs(
    params: MreditSphereParamsDict,
    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("-sphere")
    cargs.extend(map(str, params.get("position", None)))
    cargs.append(str(params.get("radius", None)))
    cargs.append(str(params.get("value", None)))
    return cargs


def mredit_voxel(
    position: list[float],
    value: float,
) -> MreditVoxelParamsDictTagged:
    """
    Build parameters.
    
    Args:
        position: change the image value within a single voxel.
        value: change the image value within a single voxel.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "voxel",
        "position": position,
        "value": value,
    }
    return params


def mredit_voxel_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MreditVoxelParamsDict` 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("position", None) is None:
        raise StyxValidationError("`position` must not be None")
    if not isinstance(params["position"], list):
        raise StyxValidationError(f'`position` has the wrong type: Received `{type(params.get("position", None))}` expected `list[float]`')
    for e in params["position"]:
        if not isinstance(e, (float, int)):
            raise StyxValidationError(f'`position` has the wrong type: Received `{type(params.get("position", None))}` expected `list[float]`')
    if params.get("value", None) is None:
        raise StyxValidationError("`value` must not be None")
    if not isinstance(params["value"], (float, int)):
        raise StyxValidationError(f'`value` has the wrong type: Received `{type(params.get("value", None))}` expected `float`')


def mredit_voxel_cargs(
    params: MreditVoxelParamsDict,
    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("-voxel")
    cargs.extend(map(str, params.get("position", None)))
    cargs.append(str(params.get("value", None)))
    return cargs


def mredit_config(
    key: str,
    value: str,
) -> MreditConfigParamsDictTagged:
    """
    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 mredit_config_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MreditConfigParamsDict` 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 mredit_config_cargs(
    params: MreditConfigParamsDict,
    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 MreditOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MreditParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType | None
    """the (optional) output image"""


def mredit_params(
    input_: InputPathType,
    plane: list[MreditPlaneParamsDict] | None = None,
    sphere: list[MreditSphereParamsDict] | None = None,
    voxel: list[MreditVoxelParamsDict] | None = None,
    scanner: bool = False,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MreditConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    output: str | None = None,
) -> MreditParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: the input image.
        plane: fill one or more planes on a particular image axis.
        sphere: draw a sphere with radius in mm.
        voxel: change the image value within a single voxel.
        scanner: indicate that coordinates are specified in scanner space,\
            rather than as voxel coordinates.
        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.
        output: the (optional) output image.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mrtrix/mredit",
        "scanner": scanner,
        "info": info,
        "quiet": quiet,
        "debug": debug,
        "force": force,
        "help": help_,
        "version": version,
        "input": input_,
    }
    if plane is not None:
        params["plane"] = plane
    if sphere is not None:
        params["sphere"] = sphere
    if voxel is not None:
        params["voxel"] = voxel
    if nthreads is not None:
        params["nthreads"] = nthreads
    if config is not None:
        params["config"] = config
    if output is not None:
        params["output"] = output
    return params


def mredit_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `MreditParamsDict` 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("plane", None) is not None:
        if not isinstance(params["plane"], list):
            raise StyxValidationError(f'`plane` has the wrong type: Received `{type(params.get("plane", None))}` expected `list[MreditPlaneParamsDict] | None`')
        for e in params["plane"]:
            mredit_plane_validate(e)
    if params.get("sphere", None) is not None:
        if not isinstance(params["sphere"], list):
            raise StyxValidationError(f'`sphere` has the wrong type: Received `{type(params.get("sphere", None))}` expected `list[MreditSphereParamsDict] | None`')
        for e in params["sphere"]:
            mredit_sphere_validate(e)
    if params.get("voxel", None) is not None:
        if not isinstance(params["voxel"], list):
            raise StyxValidationError(f'`voxel` has the wrong type: Received `{type(params.get("voxel", None))}` expected `list[MreditVoxelParamsDict] | None`')
        for e in params["voxel"]:
            mredit_voxel_validate(e)
    if params.get("scanner", False) is None:
        raise StyxValidationError("`scanner` must not be None")
    if not isinstance(params["scanner"], bool):
        raise StyxValidationError(f'`scanner` has the wrong type: Received `{type(params.get("scanner", 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[MreditConfigParamsDict] | None`')
        for e in params["config"]:
            mredit_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("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 not None:
        if not isinstance(params["output"], str):
            raise StyxValidationError(f'`output` has the wrong type: Received `{type(params.get("output", None))}` expected `str | None`')


def mredit_cargs(
    params: MreditParamsDict,
    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("mredit")
    if params.get("plane", None) is not None:
        cargs.extend([a for c in [mredit_plane_cargs(s, execution) for s in params.get("plane", None)] for a in c])
    if params.get("sphere", None) is not None:
        cargs.extend([a for c in [mredit_sphere_cargs(s, execution) for s in params.get("sphere", None)] for a in c])
    if params.get("voxel", None) is not None:
        cargs.extend([a for c in [mredit_voxel_cargs(s, execution) for s in params.get("voxel", None)] for a in c])
    if params.get("scanner", False):
        cargs.append("-scanner")
    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 [mredit_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("input", None)))
    if params.get("output", None) is not None:
        cargs.append(params.get("output", None))
    return cargs


def mredit_outputs(
    params: MreditParamsDict,
    execution: Execution,
) -> MreditOutputs:
    """
    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 = MreditOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)) if (params.get("output") is not None) else None,
    )
    return ret


def mredit_execute(
    params: MreditParamsDict,
    runner: Runner | None = None,
) -> MreditOutputs:
    """
    mredit
    
    Directly edit the intensities within an image from the command-line.
    
    A range of options are provided to enable direct editing of voxel
    intensities based on voxel / real-space coordinates. If only one image path
    is provided, the image will be edited in-place (use at own risk); if input
    and output image paths are provided, the output will contain the edited
    image, and the original image will not be modified in any way.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MreditOutputs`).
    """
    mredit_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(MREDIT_METADATA)
    params = execution.params(params)
    cargs = mredit_cargs(params, execution)
    ret = mredit_outputs(params, execution)
    execution.run(cargs)
    return ret


def mredit(
    input_: InputPathType,
    plane: list[MreditPlaneParamsDict] | None = None,
    sphere: list[MreditSphereParamsDict] | None = None,
    voxel: list[MreditVoxelParamsDict] | None = None,
    scanner: bool = False,
    info: bool = False,
    quiet: bool = False,
    debug: bool = False,
    force: bool = False,
    nthreads: int | None = None,
    config: list[MreditConfigParamsDict] | None = None,
    help_: bool = False,
    version: bool = False,
    output: str | None = None,
    runner: Runner | None = None,
) -> MreditOutputs:
    """
    mredit
    
    Directly edit the intensities within an image from the command-line.
    
    A range of options are provided to enable direct editing of voxel
    intensities based on voxel / real-space coordinates. If only one image path
    is provided, the image will be edited in-place (use at own risk); if input
    and output image paths are provided, the output will contain the edited
    image, and the original image will not be modified in any way.
    
    References:
    
    .
    
    Author: MRTrix3 Developers
    
    URL: https://www.mrtrix.org/
    
    Args:
        input_: the input image.
        plane: fill one or more planes on a particular image axis.
        sphere: draw a sphere with radius in mm.
        voxel: change the image value within a single voxel.
        scanner: indicate that coordinates are specified in scanner space,\
            rather than as voxel coordinates.
        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.
        output: the (optional) output image.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MreditOutputs`).
    """
    params = mredit_params(
        plane=plane,
        sphere=sphere,
        voxel=voxel,
        scanner=scanner,
        info=info,
        quiet=quiet,
        debug=debug,
        force=force,
        nthreads=nthreads,
        config=config,
        help_=help_,
        version=version,
        input_=input_,
        output=output,
    )
    return mredit_execute(params, runner)


__all__ = [
    "MREDIT_METADATA",
    "MreditConfigParamsDict",
    "MreditConfigParamsDictTagged",
    "MreditOutputs",
    "MreditParamsDict",
    "MreditParamsDictTagged",
    "MreditPlaneParamsDict",
    "MreditPlaneParamsDictTagged",
    "MreditSphereParamsDict",
    "MreditSphereParamsDictTagged",
    "MreditVoxelParamsDict",
    "MreditVoxelParamsDictTagged",
    "mredit",
    "mredit_config",
    "mredit_execute",
    "mredit_params",
    "mredit_plane",
    "mredit_sphere",
    "mredit_voxel",
]
