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

import typing
import pathlib
from styxdefs import *

PASTE_IMAGE_INTO_IMAGE_METADATA = Metadata(
    id="9434da4462a4b038646e9361e0a0659838206323.boutiques",
    name="PasteImageIntoImage",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_PasteImageIntoImageParamsDictNoTag = typing.TypedDict('_PasteImageIntoImageParamsDictNoTag', {
    "image_dimension": int,
    "input_canvas_image": InputPathType,
    "input_image": InputPathType,
    "output_image": str,
    "start_index": str,
    "background_label": typing.NotRequired[int | None],
    "paint_over_non_background_voxels": typing.NotRequired[typing.Literal[0, 1, 2] | None],
    "conflict_label": typing.NotRequired[int | None],
})
PasteImageIntoImageParamsDictTagged = typing.TypedDict('PasteImageIntoImageParamsDictTagged', {
    "@type": typing.Literal["ants/PasteImageIntoImage"],
    "image_dimension": int,
    "input_canvas_image": InputPathType,
    "input_image": InputPathType,
    "output_image": str,
    "start_index": str,
    "background_label": typing.NotRequired[int | None],
    "paint_over_non_background_voxels": typing.NotRequired[typing.Literal[0, 1, 2] | None],
    "conflict_label": typing.NotRequired[int | None],
})
PasteImageIntoImageParamsDict = _PasteImageIntoImageParamsDictNoTag | PasteImageIntoImageParamsDictTagged


class PasteImageIntoImageOutputs(typing.NamedTuple):
    """
    Output object returned when calling `PasteImageIntoImageParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_image_file: OutputPathType
    """The final output image with the input image pasted onto the canvas."""


def paste_image_into_image_params(
    image_dimension: int,
    input_canvas_image: InputPathType,
    input_image: InputPathType,
    output_image: str,
    start_index: str,
    background_label: int | None = None,
    paint_over_non_background_voxels: typing.Literal[0, 1, 2] | None = None,
    conflict_label: int | None = None,
) -> PasteImageIntoImageParamsDictTagged:
    """
    Build parameters.
    
    Args:
        image_dimension: Specify the dimension of the images.
        input_canvas_image: The canvas image on which the input image will be\
            pasted.
        input_image: The image to be pasted onto the canvas.
        output_image: The resulting image after pasting.
        start_index: The starting index where the input image will be pasted on\
            the canvas.
        background_label: The label value considered as background.
        paint_over_non_background_voxels: Defines behavior when the input image\
            voxel is non-background and the corresponding canvas voxel is\
            background: 0 - leave as is, 1 - replace with input voxel value, 2 -\
            replace with conflict label.
        conflict_label: The label value used for conflicting non-background\
            voxels if 'paintOverNonBackgroundVoxels' is set to 2.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/PasteImageIntoImage",
        "image_dimension": image_dimension,
        "input_canvas_image": input_canvas_image,
        "input_image": input_image,
        "output_image": output_image,
        "start_index": start_index,
    }
    if background_label is not None:
        params["background_label"] = background_label
    if paint_over_non_background_voxels is not None:
        params["paint_over_non_background_voxels"] = paint_over_non_background_voxels
    if conflict_label is not None:
        params["conflict_label"] = conflict_label
    return params


def paste_image_into_image_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `PasteImageIntoImageParamsDict` 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 `int`')
    if params.get("input_canvas_image", None) is None:
        raise StyxValidationError("`input_canvas_image` must not be None")
    if not isinstance(params["input_canvas_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input_canvas_image` has the wrong type: Received `{type(params.get("input_canvas_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("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("start_index", None) is None:
        raise StyxValidationError("`start_index` must not be None")
    if not isinstance(params["start_index"], str):
        raise StyxValidationError(f'`start_index` has the wrong type: Received `{type(params.get("start_index", None))}` expected `str`')
    if params.get("background_label", None) is not None:
        if not isinstance(params["background_label"], int):
            raise StyxValidationError(f'`background_label` has the wrong type: Received `{type(params.get("background_label", None))}` expected `int | None`')
    if params.get("paint_over_non_background_voxels", None) is not None:
        if not isinstance(params["paint_over_non_background_voxels"], int):
            raise StyxValidationError(f'`paint_over_non_background_voxels` has the wrong type: Received `{type(params.get("paint_over_non_background_voxels", None))}` expected `typing.Literal[0, 1, 2] | None`')
        if params["paint_over_non_background_voxels"] not in [0, 1, 2]:
            raise StyxValidationError("Parameter `paint_over_non_background_voxels` must be one of [0, 1, 2]")
    if params.get("conflict_label", None) is not None:
        if not isinstance(params["conflict_label"], int):
            raise StyxValidationError(f'`conflict_label` has the wrong type: Received `{type(params.get("conflict_label", None))}` expected `int | None`')


def paste_image_into_image_cargs(
    params: PasteImageIntoImageParamsDict,
    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("PasteImageIntoImage")
    cargs.append(str(params.get("image_dimension", None)))
    cargs.append(execution.input_file(params.get("input_canvas_image", None)))
    cargs.append(execution.input_file(params.get("input_image", None)))
    cargs.append(params.get("output_image", None))
    cargs.append(params.get("start_index", None))
    if params.get("background_label", None) is not None:
        cargs.append(str(params.get("background_label", None)))
    if params.get("paint_over_non_background_voxels", None) is not None:
        cargs.append(str(params.get("paint_over_non_background_voxels", None)))
    if params.get("conflict_label", None) is not None:
        cargs.append(str(params.get("conflict_label", None)))
    return cargs


def paste_image_into_image_outputs(
    params: PasteImageIntoImageParamsDict,
    execution: Execution,
) -> PasteImageIntoImageOutputs:
    """
    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 = PasteImageIntoImageOutputs(
        root=execution.output_file("."),
        output_image_file=execution.output_file(params.get("output_image", None)),
    )
    return ret


def paste_image_into_image_execute(
    params: PasteImageIntoImageParamsDict,
    runner: Runner | None = None,
) -> PasteImageIntoImageOutputs:
    """
    PasteImageIntoImage
    
    Paste the input image into the input canvas image. Depending on parameters,
    it can replace or merge existing voxel values.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `PasteImageIntoImageOutputs`).
    """
    paste_image_into_image_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(PASTE_IMAGE_INTO_IMAGE_METADATA)
    params = execution.params(params)
    cargs = paste_image_into_image_cargs(params, execution)
    ret = paste_image_into_image_outputs(params, execution)
    execution.run(cargs)
    return ret


def paste_image_into_image(
    image_dimension: int,
    input_canvas_image: InputPathType,
    input_image: InputPathType,
    output_image: str,
    start_index: str,
    background_label: int | None = None,
    paint_over_non_background_voxels: typing.Literal[0, 1, 2] | None = None,
    conflict_label: int | None = None,
    runner: Runner | None = None,
) -> PasteImageIntoImageOutputs:
    """
    PasteImageIntoImage
    
    Paste the input image into the input canvas image. Depending on parameters,
    it can replace or merge existing voxel values.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_dimension: Specify the dimension of the images.
        input_canvas_image: The canvas image on which the input image will be\
            pasted.
        input_image: The image to be pasted onto the canvas.
        output_image: The resulting image after pasting.
        start_index: The starting index where the input image will be pasted on\
            the canvas.
        background_label: The label value considered as background.
        paint_over_non_background_voxels: Defines behavior when the input image\
            voxel is non-background and the corresponding canvas voxel is\
            background: 0 - leave as is, 1 - replace with input voxel value, 2 -\
            replace with conflict label.
        conflict_label: The label value used for conflicting non-background\
            voxels if 'paintOverNonBackgroundVoxels' is set to 2.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `PasteImageIntoImageOutputs`).
    """
    params = paste_image_into_image_params(
        image_dimension=image_dimension,
        input_canvas_image=input_canvas_image,
        input_image=input_image,
        output_image=output_image,
        start_index=start_index,
        background_label=background_label,
        paint_over_non_background_voxels=paint_over_non_background_voxels,
        conflict_label=conflict_label,
    )
    return paste_image_into_image_execute(params, runner)


__all__ = [
    "PASTE_IMAGE_INTO_IMAGE_METADATA",
    "PasteImageIntoImageOutputs",
    "PasteImageIntoImageParamsDict",
    "PasteImageIntoImageParamsDictTagged",
    "paste_image_into_image",
    "paste_image_into_image_execute",
    "paste_image_into_image_params",
]
