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

import typing
import pathlib
from styxdefs import *

SET_DIRECTION_BY_MATRIX_METADATA = Metadata(
    id="04c2aca2f9311028db6b0e1a341f7527fb68cd59.boutiques",
    name="SetDirectionByMatrix",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_SetDirectionByMatrixParamsDictNoTag = typing.TypedDict('_SetDirectionByMatrixParamsDictNoTag', {
    "infile": InputPathType,
    "outfile": str,
    "direction_matrix": list[float],
})
SetDirectionByMatrixParamsDictTagged = typing.TypedDict('SetDirectionByMatrixParamsDictTagged', {
    "@type": typing.Literal["ants/SetDirectionByMatrix"],
    "infile": InputPathType,
    "outfile": str,
    "direction_matrix": list[float],
})
SetDirectionByMatrixParamsDict = _SetDirectionByMatrixParamsDictNoTag | SetDirectionByMatrixParamsDictTagged


class SetDirectionByMatrixOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SetDirectionByMatrixParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    outfile: OutputPathType
    """The output image with the new direction matrix applied."""


def set_direction_by_matrix_params(
    infile: InputPathType,
    outfile: str,
    direction_matrix: list[float],
) -> SetDirectionByMatrixParamsDictTagged:
    """
    Build parameters.
    
    Args:
        infile: The input image file.
        outfile: The output image file.
        direction_matrix: Direction matrix values in row-major order. For a 2D\
            image provide 4 values (d00 d01 d10 d11), for 3D provide 9 values (d00\
            d01 d02 d10 d11 d12 d20 d21 d22), for 4D provide 16 values.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/SetDirectionByMatrix",
        "infile": infile,
        "outfile": outfile,
        "direction_matrix": direction_matrix,
    }
    return params


def set_direction_by_matrix_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SetDirectionByMatrixParamsDict` 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("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"], str):
        raise StyxValidationError(f'`outfile` has the wrong type: Received `{type(params.get("outfile", None))}` expected `str`')
    if params.get("direction_matrix", None) is None:
        raise StyxValidationError("`direction_matrix` must not be None")
    if not isinstance(params["direction_matrix"], list):
        raise StyxValidationError(f'`direction_matrix` has the wrong type: Received `{type(params.get("direction_matrix", None))}` expected `list[float]`')
    for e in params["direction_matrix"]:
        if not isinstance(e, (float, int)):
            raise StyxValidationError(f'`direction_matrix` has the wrong type: Received `{type(params.get("direction_matrix", None))}` expected `list[float]`')


def set_direction_by_matrix_cargs(
    params: SetDirectionByMatrixParamsDict,
    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("SetDirectionByMatrix")
    cargs.append(execution.input_file(params.get("infile", None)))
    cargs.append(params.get("outfile", None))
    cargs.extend(map(str, params.get("direction_matrix", None)))
    return cargs


def set_direction_by_matrix_outputs(
    params: SetDirectionByMatrixParamsDict,
    execution: Execution,
) -> SetDirectionByMatrixOutputs:
    """
    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 = SetDirectionByMatrixOutputs(
        root=execution.output_file("."),
        outfile=execution.output_file(params.get("outfile", None)),
    )
    return ret


def set_direction_by_matrix_execute(
    params: SetDirectionByMatrixParamsDict,
    runner: Runner | None = None,
) -> SetDirectionByMatrixOutputs:
    """
    SetDirectionByMatrix
    
    Sets the direction matrix of an image. The direction matrix values are
    provided as space-separated floating-point numbers in row-major order (e.g.
    d00 d01 d02 d10 d11 d12 d20 d21 d22 for a 3D image).
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SetDirectionByMatrixOutputs`).
    """
    set_direction_by_matrix_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SET_DIRECTION_BY_MATRIX_METADATA)
    params = execution.params(params)
    cargs = set_direction_by_matrix_cargs(params, execution)
    ret = set_direction_by_matrix_outputs(params, execution)
    execution.run(cargs)
    return ret


def set_direction_by_matrix(
    infile: InputPathType,
    outfile: str,
    direction_matrix: list[float],
    runner: Runner | None = None,
) -> SetDirectionByMatrixOutputs:
    """
    SetDirectionByMatrix
    
    Sets the direction matrix of an image. The direction matrix values are
    provided as space-separated floating-point numbers in row-major order (e.g.
    d00 d01 d02 d10 d11 d12 d20 d21 d22 for a 3D image).
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        infile: The input image file.
        outfile: The output image file.
        direction_matrix: Direction matrix values in row-major order. For a 2D\
            image provide 4 values (d00 d01 d10 d11), for 3D provide 9 values (d00\
            d01 d02 d10 d11 d12 d20 d21 d22), for 4D provide 16 values.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SetDirectionByMatrixOutputs`).
    """
    params = set_direction_by_matrix_params(
        infile=infile,
        outfile=outfile,
        direction_matrix=direction_matrix,
    )
    return set_direction_by_matrix_execute(params, runner)


__all__ = [
    "SET_DIRECTION_BY_MATRIX_METADATA",
    "SetDirectionByMatrixOutputs",
    "SetDirectionByMatrixParamsDict",
    "SetDirectionByMatrixParamsDictTagged",
    "set_direction_by_matrix",
    "set_direction_by_matrix_execute",
    "set_direction_by_matrix_params",
]
