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

import typing
import pathlib
from styxdefs import *

REBASE_TENSOR_IMAGE_METADATA = Metadata(
    id="9ca2dd8e8d88e7fa58609c2b0453e98bb4f8ab16.boutiques",
    name="RebaseTensorImage",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_RebaseTensorImageParamsDictNoTag = typing.TypedDict('_RebaseTensorImageParamsDictNoTag', {
    "dimension": int,
    "infile": InputPathType,
    "outfile": InputPathType,
    "method": typing.Literal["PHYSICAL", "LOCAL"],
    "reference": typing.NotRequired[InputPathType | None],
})
RebaseTensorImageParamsDictTagged = typing.TypedDict('RebaseTensorImageParamsDictTagged', {
    "@type": typing.Literal["ants/RebaseTensorImage"],
    "dimension": int,
    "infile": InputPathType,
    "outfile": InputPathType,
    "method": typing.Literal["PHYSICAL", "LOCAL"],
    "reference": typing.NotRequired[InputPathType | None],
})
RebaseTensorImageParamsDict = _RebaseTensorImageParamsDictNoTag | RebaseTensorImageParamsDictTagged


class RebaseTensorImageOutputs(typing.NamedTuple):
    """
    Output object returned when calling `RebaseTensorImageParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    rebased_image: OutputPathType
    """The rebased tensor image."""


def rebase_tensor_image_params(
    dimension: int,
    infile: InputPathType,
    outfile: InputPathType,
    method: typing.Literal["PHYSICAL", "LOCAL"],
    reference: InputPathType | None = None,
) -> RebaseTensorImageParamsDictTagged:
    """
    Build parameters.
    
    Args:
        dimension: The dimensionality of the input image.
        infile: The input image file.
        outfile: The output image file.
        method: Method of rebasing the tensor image.
        reference: Reference image file (required if PHYSICAL or LOCAL method\
            is chosen).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/RebaseTensorImage",
        "dimension": dimension,
        "infile": infile,
        "outfile": outfile,
        "method": method,
    }
    if reference is not None:
        params["reference"] = reference
    return params


def rebase_tensor_image_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `RebaseTensorImageParamsDict` 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("dimension", None) is None:
        raise StyxValidationError("`dimension` must not be None")
    if not isinstance(params["dimension"], int):
        raise StyxValidationError(f'`dimension` has the wrong type: Received `{type(params.get("dimension", None))}` expected `int`')
    if params.get("infile", None) is None:
        raise StyxValidationError("`infile` must not be None")
    if not isinstance(params["infile"], (pathlib.Path, str)):
        raise StyxValidationError(f'`infile` has the wrong type: Received `{type(params.get("infile", None))}` expected `InputPathType`')
    if params.get("outfile", None) is None:
        raise StyxValidationError("`outfile` must not be None")
    if not isinstance(params["outfile"], (pathlib.Path, str)):
        raise StyxValidationError(f'`outfile` has the wrong type: Received `{type(params.get("outfile", None))}` expected `InputPathType`')
    if params.get("method", None) is None:
        raise StyxValidationError("`method` must not be None")
    if not isinstance(params["method"], str):
        raise StyxValidationError(f'`method` has the wrong type: Received `{type(params.get("method", None))}` expected `typing.Literal["PHYSICAL", "LOCAL"]`')
    if params["method"] not in ["PHYSICAL", "LOCAL"]:
        raise StyxValidationError("Parameter `method` must be one of [\"PHYSICAL\", \"LOCAL\"]")
    if params.get("reference", None) is not None:
        if not isinstance(params["reference"], (pathlib.Path, str)):
            raise StyxValidationError(f'`reference` has the wrong type: Received `{type(params.get("reference", None))}` expected `InputPathType | None`')


def rebase_tensor_image_cargs(
    params: RebaseTensorImageParamsDict,
    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("RebaseTensorImage")
    cargs.append(str(params.get("dimension", None)))
    cargs.append(execution.input_file(params.get("infile", None)))
    cargs.append(execution.input_file(params.get("outfile", None)))
    cargs.append(params.get("method", None))
    if params.get("reference", None) is not None:
        cargs.append(execution.input_file(params.get("reference", None)))
    return cargs


def rebase_tensor_image_outputs(
    params: RebaseTensorImageParamsDict,
    execution: Execution,
) -> RebaseTensorImageOutputs:
    """
    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 = RebaseTensorImageOutputs(
        root=execution.output_file("."),
        rebased_image=execution.output_file(pathlib.Path(params.get("outfile", None)).name),
    )
    return ret


def rebase_tensor_image_execute(
    params: RebaseTensorImageParamsDict,
    runner: Runner | None = None,
) -> RebaseTensorImageOutputs:
    """
    RebaseTensorImage
    
    Rebase Tensor Image using specified dimensionality and method.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `RebaseTensorImageOutputs`).
    """
    rebase_tensor_image_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(REBASE_TENSOR_IMAGE_METADATA)
    params = execution.params(params)
    cargs = rebase_tensor_image_cargs(params, execution)
    ret = rebase_tensor_image_outputs(params, execution)
    execution.run(cargs)
    return ret


def rebase_tensor_image(
    dimension: int,
    infile: InputPathType,
    outfile: InputPathType,
    method: typing.Literal["PHYSICAL", "LOCAL"],
    reference: InputPathType | None = None,
    runner: Runner | None = None,
) -> RebaseTensorImageOutputs:
    """
    RebaseTensorImage
    
    Rebase Tensor Image using specified dimensionality and method.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        dimension: The dimensionality of the input image.
        infile: The input image file.
        outfile: The output image file.
        method: Method of rebasing the tensor image.
        reference: Reference image file (required if PHYSICAL or LOCAL method\
            is chosen).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `RebaseTensorImageOutputs`).
    """
    params = rebase_tensor_image_params(
        dimension=dimension,
        infile=infile,
        outfile=outfile,
        method=method,
        reference=reference,
    )
    return rebase_tensor_image_execute(params, runner)


__all__ = [
    "REBASE_TENSOR_IMAGE_METADATA",
    "RebaseTensorImageOutputs",
    "RebaseTensorImageParamsDict",
    "RebaseTensorImageParamsDictTagged",
    "rebase_tensor_image",
    "rebase_tensor_image_execute",
    "rebase_tensor_image_params",
]
