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

import typing
import pathlib
from styxdefs import *

ANTS_INTRODUCTION_SH_METADATA = Metadata(
    id="2466e97f47783a3d8aa1ce52756260c6e54db2c7.boutiques",
    name="antsIntroduction.sh",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsIntroductionShParamsDictNoTag = typing.TypedDict('_AntsIntroductionShParamsDictNoTag', {
    "image_dimension": typing.Literal[2, 3],
    "reference_image": InputPathType,
    "input_image": InputPathType,
    "force": typing.NotRequired[bool | None],
    "labels_in_fixed_image_space": typing.NotRequired[str | None],
    "max_iterations": typing.NotRequired[int | None],
    "n4_bias_field_correction": typing.NotRequired[bool | None],
    "outprefix": typing.NotRequired[str | None],
    "quality_check": typing.NotRequired[bool | None],
    "similarity_metric": typing.NotRequired[str | None],
    "transformation_model": typing.NotRequired[str | None],
})
AntsIntroductionShParamsDictTagged = typing.TypedDict('AntsIntroductionShParamsDictTagged', {
    "@type": typing.Literal["ants/antsIntroduction.sh"],
    "image_dimension": typing.Literal[2, 3],
    "reference_image": InputPathType,
    "input_image": InputPathType,
    "force": typing.NotRequired[bool | None],
    "labels_in_fixed_image_space": typing.NotRequired[str | None],
    "max_iterations": typing.NotRequired[int | None],
    "n4_bias_field_correction": typing.NotRequired[bool | None],
    "outprefix": typing.NotRequired[str | None],
    "quality_check": typing.NotRequired[bool | None],
    "similarity_metric": typing.NotRequired[str | None],
    "transformation_model": typing.NotRequired[str | None],
})
AntsIntroductionShParamsDict = _AntsIntroductionShParamsDictNoTag | AntsIntroductionShParamsDictTagged


class AntsIntroductionShOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsIntroductionShParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def ants_introduction_sh_params(
    image_dimension: typing.Literal[2, 3],
    reference_image: InputPathType,
    input_image: InputPathType,
    force: bool | None = None,
    labels_in_fixed_image_space: str | None = None,
    max_iterations: int | None = None,
    n4_bias_field_correction: bool | None = None,
    outprefix: str | None = None,
    quality_check: bool | None = None,
    similarity_metric: str | None = None,
    transformation_model: str | None = None,
) -> AntsIntroductionShParamsDictTagged:
    """
    Build parameters.
    
    Args:
        image_dimension: Image dimension for registration: 2 or 3.
        reference_image: Reference image for registration.
        input_image: Input image to be registered.
        force: Force script to proceed even if headers may be incompatible.
        labels_in_fixed_image_space: Labels in fixed image space to deform to\
            moving image.
        max_iterations: Maximum number of iterations.
        n4_bias_field_correction: N4 Bias Field Correction of moving image: 0\
            for off, 1 for on.
        outprefix: A prefix that is prepended to all output files.
        quality_check: Perform a Quality Check (QC) of the result: 0 for off, 1\
            for on.
        similarity_metric: Type of similarity metric used for registration.
        transformation_model: Type of transformation model used for\
            registration.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/antsIntroduction.sh",
        "image_dimension": image_dimension,
        "reference_image": reference_image,
        "input_image": input_image,
    }
    if force is not None:
        params["force"] = force
    if labels_in_fixed_image_space is not None:
        params["labels_in_fixed_image_space"] = labels_in_fixed_image_space
    if max_iterations is not None:
        params["max_iterations"] = max_iterations
    if n4_bias_field_correction is not None:
        params["n4_bias_field_correction"] = n4_bias_field_correction
    if outprefix is not None:
        params["outprefix"] = outprefix
    if quality_check is not None:
        params["quality_check"] = quality_check
    if similarity_metric is not None:
        params["similarity_metric"] = similarity_metric
    if transformation_model is not None:
        params["transformation_model"] = transformation_model
    return params


def ants_introduction_sh_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsIntroductionShParamsDict` 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[2, 3]`')
    if params["image_dimension"] not in [2, 3]:
        raise StyxValidationError("Parameter `image_dimension` must be one of [2, 3]")
    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("input_image", None) is None:
        raise StyxValidationError("`input_image` must not be None")
    if not isinstance(params["input_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input_image` has the wrong type: Received `{type(params.get("input_image", None))}` expected `InputPathType`')
    if params.get("force", None) is not None:
        if not isinstance(params["force"], bool):
            raise StyxValidationError(f'`force` has the wrong type: Received `{type(params.get("force", None))}` expected `bool | None`')
    if params.get("labels_in_fixed_image_space", None) is not None:
        if not isinstance(params["labels_in_fixed_image_space"], str):
            raise StyxValidationError(f'`labels_in_fixed_image_space` has the wrong type: Received `{type(params.get("labels_in_fixed_image_space", None))}` expected `str | None`')
    if params.get("max_iterations", None) is not None:
        if not isinstance(params["max_iterations"], int):
            raise StyxValidationError(f'`max_iterations` has the wrong type: Received `{type(params.get("max_iterations", None))}` expected `int | None`')
    if params.get("n4_bias_field_correction", None) is not None:
        if not isinstance(params["n4_bias_field_correction"], bool):
            raise StyxValidationError(f'`n4_bias_field_correction` has the wrong type: Received `{type(params.get("n4_bias_field_correction", None))}` expected `bool | None`')
    if params.get("outprefix", None) is not None:
        if not isinstance(params["outprefix"], str):
            raise StyxValidationError(f'`outprefix` has the wrong type: Received `{type(params.get("outprefix", None))}` expected `str | None`')
    if params.get("quality_check", None) is not None:
        if not isinstance(params["quality_check"], bool):
            raise StyxValidationError(f'`quality_check` has the wrong type: Received `{type(params.get("quality_check", None))}` expected `bool | None`')
    if params.get("similarity_metric", None) is not None:
        if not isinstance(params["similarity_metric"], str):
            raise StyxValidationError(f'`similarity_metric` has the wrong type: Received `{type(params.get("similarity_metric", None))}` expected `str | None`')
    if params.get("transformation_model", None) is not None:
        if not isinstance(params["transformation_model"], str):
            raise StyxValidationError(f'`transformation_model` has the wrong type: Received `{type(params.get("transformation_model", None))}` expected `str | None`')


def ants_introduction_sh_cargs(
    params: AntsIntroductionShParamsDict,
    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("antsIntroduction.sh")
    cargs.extend([
        "-d",
        str(params.get("image_dimension", None))
    ])
    cargs.extend([
        "-r",
        execution.input_file(params.get("reference_image", None))
    ])
    cargs.extend([
        "-i",
        execution.input_file(params.get("input_image", None))
    ])
    if params.get("force", None) is not None:
        cargs.extend([
            "-f",
            ("1" if params.get("force", None) else "0")
        ])
    if params.get("labels_in_fixed_image_space", None) is not None:
        cargs.extend([
            "-l",
            params.get("labels_in_fixed_image_space", None)
        ])
    if params.get("max_iterations", None) is not None:
        cargs.extend([
            "-m",
            str(params.get("max_iterations", None))
        ])
    if params.get("n4_bias_field_correction", None) is not None:
        cargs.extend([
            "-n",
            ("1" if params.get("n4_bias_field_correction", None) else "0")
        ])
    if params.get("outprefix", None) is not None:
        cargs.extend([
            "-o",
            params.get("outprefix", None)
        ])
    if params.get("quality_check", None) is not None:
        cargs.extend([
            "-q",
            ("1" if params.get("quality_check", None) else "0")
        ])
    if params.get("similarity_metric", None) is not None:
        cargs.extend([
            "-s",
            params.get("similarity_metric", None)
        ])
    if params.get("transformation_model", None) is not None:
        cargs.extend([
            "-t",
            params.get("transformation_model", None)
        ])
    return cargs


def ants_introduction_sh_outputs(
    params: AntsIntroductionShParamsDict,
    execution: Execution,
) -> AntsIntroductionShOutputs:
    """
    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 = AntsIntroductionShOutputs(
        root=execution.output_file("."),
    )
    return ret


def ants_introduction_sh_execute(
    params: AntsIntroductionShParamsDict,
    runner: Runner | None = None,
) -> AntsIntroductionShOutputs:
    """
    antsIntroduction.sh
    
    Script for registration using ANTS with compulsory and optional arguments.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsIntroductionShOutputs`).
    """
    ants_introduction_sh_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTS_INTRODUCTION_SH_METADATA)
    params = execution.params(params)
    cargs = ants_introduction_sh_cargs(params, execution)
    ret = ants_introduction_sh_outputs(params, execution)
    execution.run(cargs)
    return ret


def ants_introduction_sh(
    image_dimension: typing.Literal[2, 3],
    reference_image: InputPathType,
    input_image: InputPathType,
    force: bool | None = None,
    labels_in_fixed_image_space: str | None = None,
    max_iterations: int | None = None,
    n4_bias_field_correction: bool | None = None,
    outprefix: str | None = None,
    quality_check: bool | None = None,
    similarity_metric: str | None = None,
    transformation_model: str | None = None,
    runner: Runner | None = None,
) -> AntsIntroductionShOutputs:
    """
    antsIntroduction.sh
    
    Script for registration using ANTS with compulsory and optional arguments.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: Image dimension for registration: 2 or 3.
        reference_image: Reference image for registration.
        input_image: Input image to be registered.
        force: Force script to proceed even if headers may be incompatible.
        labels_in_fixed_image_space: Labels in fixed image space to deform to\
            moving image.
        max_iterations: Maximum number of iterations.
        n4_bias_field_correction: N4 Bias Field Correction of moving image: 0\
            for off, 1 for on.
        outprefix: A prefix that is prepended to all output files.
        quality_check: Perform a Quality Check (QC) of the result: 0 for off, 1\
            for on.
        similarity_metric: Type of similarity metric used for registration.
        transformation_model: Type of transformation model used for\
            registration.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsIntroductionShOutputs`).
    """
    params = ants_introduction_sh_params(
        image_dimension=image_dimension,
        reference_image=reference_image,
        input_image=input_image,
        force=force,
        labels_in_fixed_image_space=labels_in_fixed_image_space,
        max_iterations=max_iterations,
        n4_bias_field_correction=n4_bias_field_correction,
        outprefix=outprefix,
        quality_check=quality_check,
        similarity_metric=similarity_metric,
        transformation_model=transformation_model,
    )
    return ants_introduction_sh_execute(params, runner)


__all__ = [
    "ANTS_INTRODUCTION_SH_METADATA",
    "AntsIntroductionShOutputs",
    "AntsIntroductionShParamsDict",
    "AntsIntroductionShParamsDictTagged",
    "ants_introduction_sh",
    "ants_introduction_sh_execute",
    "ants_introduction_sh_params",
]
