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

import typing
import pathlib
from styxdefs import *

ANTS_REGISTRATION_SY_NQUICK_SH_METADATA = Metadata(
    id="9bf492799cfd56f1976ba1ef5ef603c832961ac8.boutiques",
    name="antsRegistrationSyNQuick.sh",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsRegistrationSyNquickShParamsDictNoTag = typing.TypedDict('_AntsRegistrationSyNquickShParamsDictNoTag', {
    "dimensionality": typing.Literal[2, 3],
    "fixed_image": InputPathType,
    "moving_image": InputPathType,
    "output_prefix": str,
    "transform_type": typing.NotRequired[typing.Literal["s", "b"] | None],
})
AntsRegistrationSyNquickShParamsDictTagged = typing.TypedDict('AntsRegistrationSyNquickShParamsDictTagged', {
    "@type": typing.Literal["ants/antsRegistrationSyNQuick.sh"],
    "dimensionality": typing.Literal[2, 3],
    "fixed_image": InputPathType,
    "moving_image": InputPathType,
    "output_prefix": str,
    "transform_type": typing.NotRequired[typing.Literal["s", "b"] | None],
})
AntsRegistrationSyNquickShParamsDict = _AntsRegistrationSyNquickShParamsDictNoTag | AntsRegistrationSyNquickShParamsDictTagged


class AntsRegistrationSyNquickShOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsRegistrationSyNquickShParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_transform: OutputPathType
    """Affine transformation matrix resulting from registration."""
    output_warp: OutputPathType
    """Warp field resulting from the registration."""
    output_inverse_warp: OutputPathType
    """Inverse warp field resulting from the registration."""
    output_warped_image: OutputPathType
    """Warped moving image."""


def ants_registration_sy_nquick_sh_params(
    dimensionality: typing.Literal[2, 3],
    fixed_image: InputPathType,
    moving_image: InputPathType,
    output_prefix: str,
    transform_type: typing.Literal["s", "b"] | None = None,
) -> AntsRegistrationSyNquickShParamsDictTagged:
    """
    Build parameters.
    
    Args:
        dimensionality: Dimensionality of the images (2 or 3).
        fixed_image: Fixed image to which the moving image is registered.
        moving_image: Moving image that is registered to the fixed image.
        output_prefix: Prefix for the output files.
        transform_type: Type of transform: 's' for SyN, 'b' for B-spline SyN.\
            Default is 's'.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/antsRegistrationSyNQuick.sh",
        "dimensionality": dimensionality,
        "fixed_image": fixed_image,
        "moving_image": moving_image,
        "output_prefix": output_prefix,
    }
    if transform_type is not None:
        params["transform_type"] = transform_type
    return params


def ants_registration_sy_nquick_sh_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsRegistrationSyNquickShParamsDict` 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 None:
        raise StyxValidationError("`dimensionality` must not be 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]`')
    if params["dimensionality"] not in [2, 3]:
        raise StyxValidationError("Parameter `dimensionality` must be one of [2, 3]")
    if params.get("fixed_image", None) is None:
        raise StyxValidationError("`fixed_image` must not be None")
    if not isinstance(params["fixed_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`fixed_image` has the wrong type: Received `{type(params.get("fixed_image", None))}` expected `InputPathType`')
    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_prefix", None) is None:
        raise StyxValidationError("`output_prefix` must not be None")
    if not isinstance(params["output_prefix"], str):
        raise StyxValidationError(f'`output_prefix` has the wrong type: Received `{type(params.get("output_prefix", None))}` expected `str`')
    if params.get("transform_type", None) is not None:
        if not isinstance(params["transform_type"], str):
            raise StyxValidationError(f'`transform_type` has the wrong type: Received `{type(params.get("transform_type", None))}` expected `typing.Literal["s", "b"] | None`')
        if params["transform_type"] not in ["s", "b"]:
            raise StyxValidationError("Parameter `transform_type` must be one of [\"s\", \"b\"]")


def ants_registration_sy_nquick_sh_cargs(
    params: AntsRegistrationSyNquickShParamsDict,
    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("antsRegistrationSyNQuick.sh")
    cargs.extend([
        "-d",
        str(params.get("dimensionality", None))
    ])
    cargs.extend([
        "-f",
        execution.input_file(params.get("fixed_image", None))
    ])
    cargs.extend([
        "-m",
        execution.input_file(params.get("moving_image", None))
    ])
    cargs.extend([
        "-o",
        params.get("output_prefix", None)
    ])
    if params.get("transform_type", None) is not None:
        cargs.append(params.get("transform_type", None))
    return cargs


def ants_registration_sy_nquick_sh_outputs(
    params: AntsRegistrationSyNquickShParamsDict,
    execution: Execution,
) -> AntsRegistrationSyNquickShOutputs:
    """
    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 = AntsRegistrationSyNquickShOutputs(
        root=execution.output_file("."),
        output_transform=execution.output_file(params.get("output_prefix", None) + "0GenericAffine.mat"),
        output_warp=execution.output_file(params.get("output_prefix", None) + "1Warp.nii.gz"),
        output_inverse_warp=execution.output_file(params.get("output_prefix", None) + "1InverseWarp.nii.gz"),
        output_warped_image=execution.output_file(params.get("output_prefix", None) + "Warped.nii.gz"),
    )
    return ret


def ants_registration_sy_nquick_sh_execute(
    params: AntsRegistrationSyNquickShParamsDict,
    runner: Runner | None = None,
) -> AntsRegistrationSyNquickShOutputs:
    """
    antsRegistrationSyNQuick.sh
    
    A script to quickly compute a SyN-based registration between two images
    using ANTS.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsRegistrationSyNquickShOutputs`).
    """
    ants_registration_sy_nquick_sh_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_REGISTRATION_SY_NQUICK_SH_METADATA)
    params = execution.params(params)
    cargs = ants_registration_sy_nquick_sh_cargs(params, execution)
    ret = ants_registration_sy_nquick_sh_outputs(params, execution)
    execution.run(cargs)
    return ret


def ants_registration_sy_nquick_sh(
    dimensionality: typing.Literal[2, 3],
    fixed_image: InputPathType,
    moving_image: InputPathType,
    output_prefix: str,
    transform_type: typing.Literal["s", "b"] | None = None,
    runner: Runner | None = None,
) -> AntsRegistrationSyNquickShOutputs:
    """
    antsRegistrationSyNQuick.sh
    
    A script to quickly compute a SyN-based registration between two images
    using ANTS.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        dimensionality: Dimensionality of the images (2 or 3).
        fixed_image: Fixed image to which the moving image is registered.
        moving_image: Moving image that is registered to the fixed image.
        output_prefix: Prefix for the output files.
        transform_type: Type of transform: 's' for SyN, 'b' for B-spline SyN.\
            Default is 's'.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsRegistrationSyNquickShOutputs`).
    """
    params = ants_registration_sy_nquick_sh_params(
        dimensionality=dimensionality,
        fixed_image=fixed_image,
        moving_image=moving_image,
        output_prefix=output_prefix,
        transform_type=transform_type,
    )
    return ants_registration_sy_nquick_sh_execute(params, runner)


__all__ = [
    "ANTS_REGISTRATION_SY_NQUICK_SH_METADATA",
    "AntsRegistrationSyNquickShOutputs",
    "AntsRegistrationSyNquickShParamsDict",
    "AntsRegistrationSyNquickShParamsDictTagged",
    "ants_registration_sy_nquick_sh",
    "ants_registration_sy_nquick_sh_execute",
    "ants_registration_sy_nquick_sh_params",
]
