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

import typing
import pathlib
from styxdefs import *

ANTS_ALIGN_ORIGIN_METADATA = Metadata(
    id="a2901ef9bcab2f861ffe659998f028f791c5e4fd.boutiques",
    name="antsAlignOrigin",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsAlignOriginParamsDictNoTag = typing.TypedDict('_AntsAlignOriginParamsDictNoTag', {
    "dimensionality": typing.NotRequired[typing.Literal[2, 3] | None],
    "input": InputPathType,
    "reference_image": InputPathType,
    "output": str,
})
AntsAlignOriginParamsDictTagged = typing.TypedDict('AntsAlignOriginParamsDictTagged', {
    "@type": typing.Literal["ants/antsAlignOrigin"],
    "dimensionality": typing.NotRequired[typing.Literal[2, 3] | None],
    "input": InputPathType,
    "reference_image": InputPathType,
    "output": str,
})
AntsAlignOriginParamsDict = _AntsAlignOriginParamsDictNoTag | AntsAlignOriginParamsDictTagged


class AntsAlignOriginOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsAlignOriginParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    aligned_image: OutputPathType
    """The output is the aligned image."""


def ants_align_origin_params(
    input_: InputPathType,
    reference_image: InputPathType,
    output: str,
    dimensionality: typing.Literal[2, 3] | None = None,
) -> AntsAlignOriginParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: Currently, the only input objects supported are image objects.\
            However, the current framework allows for warping of other objects such\
            as meshes and point sets.
        reference_image: For warping input images, the reference image defines\
            the spacing, origin, size, and direction of the output warped image.
        output: One can either output the warped image or, if the boolean is\
            set, one can print out the displacement field based on the composite\
            transform and the reference image.
        dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, antsWarp tries to infer\
            the dimensionality from the input image.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/antsAlignOrigin",
        "input": input_,
        "reference_image": reference_image,
        "output": output,
    }
    if dimensionality is not None:
        params["dimensionality"] = dimensionality
    return params


def ants_align_origin_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsAlignOriginParamsDict` 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("dimensionality", None) is not None:
        if not isinstance(params["dimensionality"], int):
            raise StyxValidationError(f'`dimensionality` has the wrong type: Received `{type(params.get("dimensionality", None))}` expected `typing.Literal[2, 3] | None`')
        if params["dimensionality"] not in [2, 3]:
            raise StyxValidationError("Parameter `dimensionality` must be one of [2, 3]")
    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("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("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 ants_align_origin_cargs(
    params: AntsAlignOriginParamsDict,
    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("antsAlignOrigin")
    if params.get("dimensionality", None) is not None:
        cargs.extend([
            "--dimensionality",
            str(params.get("dimensionality", None))
        ])
    cargs.extend([
        "--input",
        execution.input_file(params.get("input", None))
    ])
    cargs.extend([
        "--reference-image",
        execution.input_file(params.get("reference_image", None))
    ])
    cargs.extend([
        "--output",
        params.get("output", None)
    ])
    return cargs


def ants_align_origin_outputs(
    params: AntsAlignOriginParamsDict,
    execution: Execution,
) -> AntsAlignOriginOutputs:
    """
    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 = AntsAlignOriginOutputs(
        root=execution.output_file("."),
        aligned_image=execution.output_file(params.get("output", None)),
    )
    return ret


def ants_align_origin_execute(
    params: AntsAlignOriginParamsDict,
    runner: Runner | None = None,
) -> AntsAlignOriginOutputs:
    """
    antsAlignOrigin
    
    antsAlignOrigin, applied to an input image, transforms it according to a
    reference image and a transform (or a set of transforms).
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsAlignOriginOutputs`).
    """
    ants_align_origin_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_ALIGN_ORIGIN_METADATA)
    params = execution.params(params)
    cargs = ants_align_origin_cargs(params, execution)
    ret = ants_align_origin_outputs(params, execution)
    execution.run(cargs)
    return ret


def ants_align_origin(
    input_: InputPathType,
    reference_image: InputPathType,
    output: str,
    dimensionality: typing.Literal[2, 3] | None = None,
    runner: Runner | None = None,
) -> AntsAlignOriginOutputs:
    """
    antsAlignOrigin
    
    antsAlignOrigin, applied to an input image, transforms it according to a
    reference image and a transform (or a set of transforms).
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        input_: Currently, the only input objects supported are image objects.\
            However, the current framework allows for warping of other objects such\
            as meshes and point sets.
        reference_image: For warping input images, the reference image defines\
            the spacing, origin, size, and direction of the output warped image.
        output: One can either output the warped image or, if the boolean is\
            set, one can print out the displacement field based on the composite\
            transform and the reference image.
        dimensionality: This option forces the image to be treated as a\
            specified-dimensional image. If not specified, antsWarp tries to infer\
            the dimensionality from the input image.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsAlignOriginOutputs`).
    """
    params = ants_align_origin_params(
        dimensionality=dimensionality,
        input_=input_,
        reference_image=reference_image,
        output=output,
    )
    return ants_align_origin_execute(params, runner)


__all__ = [
    "ANTS_ALIGN_ORIGIN_METADATA",
    "AntsAlignOriginOutputs",
    "AntsAlignOriginParamsDict",
    "AntsAlignOriginParamsDictTagged",
    "ants_align_origin",
    "ants_align_origin_execute",
    "ants_align_origin_params",
]
