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

import typing
import pathlib
from styxdefs import *

WARP_TIME_SERIES_IMAGE_MULTI_TRANSFORM_METADATA = Metadata(
    id="231dae6842dbb185b4794c2227e0956c3df99895.boutiques",
    name="WarpTimeSeriesImageMultiTransform",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_WarpTimeSeriesImageMultiTransformParamsDictNoTag = typing.TypedDict('_WarpTimeSeriesImageMultiTransformParamsDictNoTag', {
    "image_dimension": typing.Literal[3, 4],
    "moving_image": InputPathType,
    "output_image": str,
    "reference_image": InputPathType,
    "transforms": list[str],
    "interpolation": typing.NotRequired[typing.Literal["NearestNeighbor", "BSpline"] | None],
})
WarpTimeSeriesImageMultiTransformParamsDictTagged = typing.TypedDict('WarpTimeSeriesImageMultiTransformParamsDictTagged', {
    "@type": typing.Literal["ants/WarpTimeSeriesImageMultiTransform"],
    "image_dimension": typing.Literal[3, 4],
    "moving_image": InputPathType,
    "output_image": str,
    "reference_image": InputPathType,
    "transforms": list[str],
    "interpolation": typing.NotRequired[typing.Literal["NearestNeighbor", "BSpline"] | None],
})
WarpTimeSeriesImageMultiTransformParamsDict = _WarpTimeSeriesImageMultiTransformParamsDictNoTag | WarpTimeSeriesImageMultiTransformParamsDictTagged


class WarpTimeSeriesImageMultiTransformOutputs(typing.NamedTuple):
    """
    Output object returned when calling `WarpTimeSeriesImageMultiTransformParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_image_result: OutputPathType
    """The transformed image that is saved as output."""


def warp_time_series_image_multi_transform_params(
    image_dimension: typing.Literal[3, 4],
    moving_image: InputPathType,
    output_image: str,
    reference_image: InputPathType,
    transforms: list[str],
    interpolation: typing.Literal["NearestNeighbor", "BSpline"] | None = None,
) -> WarpTimeSeriesImageMultiTransformParamsDictTagged:
    """
    Build parameters.
    
    Args:
        image_dimension: The dimensionality of the input images (3D or 4D).
        moving_image: The image to which the transformation will be applied. It\
            can be a 3D image with vector voxels or a 4D image with scalar voxels.
        output_image: The output image after transformation. It is resampled\
            based on the reference image domain.
        reference_image: The reference image that defines the space into which\
            the input image will be warped.
        transforms: A list of transformation files, such as affine\
            transformation matrices and warps, applied in sequence.
        interpolation: Specifies the type of interpolation to use: Nearest\
            Neighbor or 3rd order B-Spline.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/WarpTimeSeriesImageMultiTransform",
        "image_dimension": image_dimension,
        "moving_image": moving_image,
        "output_image": output_image,
        "reference_image": reference_image,
        "transforms": transforms,
    }
    if interpolation is not None:
        params["interpolation"] = interpolation
    return params


def warp_time_series_image_multi_transform_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `WarpTimeSeriesImageMultiTransformParamsDict` 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("image_dimension", None) is None:
        raise StyxValidationError("`image_dimension` must not be None")
    if not isinstance(params["image_dimension"], int):
        raise StyxValidationError(f'`image_dimension` has the wrong type: Received `{type(params.get("image_dimension", None))}` expected `typing.Literal[3, 4]`')
    if params["image_dimension"] not in [3, 4]:
        raise StyxValidationError("Parameter `image_dimension` must be one of [3, 4]")
    if params.get("moving_image", None) is None:
        raise StyxValidationError("`moving_image` must not be None")
    if not isinstance(params["moving_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`moving_image` has the wrong type: Received `{type(params.get("moving_image", None))}` expected `InputPathType`')
    if params.get("output_image", None) is None:
        raise StyxValidationError("`output_image` must not be None")
    if not isinstance(params["output_image"], str):
        raise StyxValidationError(f'`output_image` has the wrong type: Received `{type(params.get("output_image", None))}` expected `str`')
    if params.get("reference_image", None) is None:
        raise StyxValidationError("`reference_image` must not be None")
    if not isinstance(params["reference_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`reference_image` has the wrong type: Received `{type(params.get("reference_image", None))}` expected `InputPathType`')
    if params.get("transforms", None) is None:
        raise StyxValidationError("`transforms` must not be None")
    if not isinstance(params["transforms"], list):
        raise StyxValidationError(f'`transforms` has the wrong type: Received `{type(params.get("transforms", None))}` expected `list[str]`')
    for e in params["transforms"]:
        if not isinstance(e, str):
            raise StyxValidationError(f'`transforms` has the wrong type: Received `{type(params.get("transforms", None))}` expected `list[str]`')
    if params.get("interpolation", None) is not None:
        if not isinstance(params["interpolation"], str):
            raise StyxValidationError(f'`interpolation` has the wrong type: Received `{type(params.get("interpolation", None))}` expected `typing.Literal["NearestNeighbor", "BSpline"] | None`')
        if params["interpolation"] not in ["NearestNeighbor", "BSpline"]:
            raise StyxValidationError("Parameter `interpolation` must be one of [\"NearestNeighbor\", \"BSpline\"]")


def warp_time_series_image_multi_transform_cargs(
    params: WarpTimeSeriesImageMultiTransformParamsDict,
    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("WarpTimeSeriesImageMultiTransform")
    cargs.append(str(params.get("image_dimension", None)))
    cargs.append(execution.input_file(params.get("moving_image", None)))
    cargs.append(params.get("output_image", None))
    cargs.extend([
        "-R",
        execution.input_file(params.get("reference_image", None))
    ])
    cargs.extend(params.get("transforms", None))
    if params.get("interpolation", None) is not None:
        cargs.append(params.get("interpolation", None))
    return cargs


def warp_time_series_image_multi_transform_outputs(
    params: WarpTimeSeriesImageMultiTransformParamsDict,
    execution: Execution,
) -> WarpTimeSeriesImageMultiTransformOutputs:
    """
    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 = WarpTimeSeriesImageMultiTransformOutputs(
        root=execution.output_file("."),
        output_image_result=execution.output_file(params.get("output_image", None)),
    )
    return ret


def warp_time_series_image_multi_transform_execute(
    params: WarpTimeSeriesImageMultiTransformParamsDict,
    runner: Runner | None = None,
) -> WarpTimeSeriesImageMultiTransformOutputs:
    """
    WarpTimeSeriesImageMultiTransform
    
    WarpTimeSeriesImageMultiTransform is a tool used to apply a series of
    transformations to a time series image, either forward or reverse, using
    affine transforms and warps.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `WarpTimeSeriesImageMultiTransformOutputs`).
    """
    warp_time_series_image_multi_transform_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(WARP_TIME_SERIES_IMAGE_MULTI_TRANSFORM_METADATA)
    params = execution.params(params)
    cargs = warp_time_series_image_multi_transform_cargs(params, execution)
    ret = warp_time_series_image_multi_transform_outputs(params, execution)
    execution.run(cargs)
    return ret


def warp_time_series_image_multi_transform(
    image_dimension: typing.Literal[3, 4],
    moving_image: InputPathType,
    output_image: str,
    reference_image: InputPathType,
    transforms: list[str],
    interpolation: typing.Literal["NearestNeighbor", "BSpline"] | None = None,
    runner: Runner | None = None,
) -> WarpTimeSeriesImageMultiTransformOutputs:
    """
    WarpTimeSeriesImageMultiTransform
    
    WarpTimeSeriesImageMultiTransform is a tool used to apply a series of
    transformations to a time series image, either forward or reverse, using
    affine transforms and warps.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: The dimensionality of the input images (3D or 4D).
        moving_image: The image to which the transformation will be applied. It\
            can be a 3D image with vector voxels or a 4D image with scalar voxels.
        output_image: The output image after transformation. It is resampled\
            based on the reference image domain.
        reference_image: The reference image that defines the space into which\
            the input image will be warped.
        transforms: A list of transformation files, such as affine\
            transformation matrices and warps, applied in sequence.
        interpolation: Specifies the type of interpolation to use: Nearest\
            Neighbor or 3rd order B-Spline.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `WarpTimeSeriesImageMultiTransformOutputs`).
    """
    params = warp_time_series_image_multi_transform_params(
        image_dimension=image_dimension,
        moving_image=moving_image,
        output_image=output_image,
        reference_image=reference_image,
        transforms=transforms,
        interpolation=interpolation,
    )
    return warp_time_series_image_multi_transform_execute(params, runner)


__all__ = [
    "WARP_TIME_SERIES_IMAGE_MULTI_TRANSFORM_METADATA",
    "WarpTimeSeriesImageMultiTransformOutputs",
    "WarpTimeSeriesImageMultiTransformParamsDict",
    "WarpTimeSeriesImageMultiTransformParamsDictTagged",
    "warp_time_series_image_multi_transform",
    "warp_time_series_image_multi_transform_execute",
    "warp_time_series_image_multi_transform_params",
]
