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

import typing
import pathlib
from styxdefs import *

CONVERT_TRANSFORM_FILE_METADATA = Metadata(
    id="09238b9afb3b35db70adc70f6459e5edc8963971.boutiques",
    name="ConvertTransformFile",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_ConvertTransformFileParamsDictNoTag = typing.TypedDict('_ConvertTransformFileParamsDictNoTag', {
    "dimensions": int,
    "input_transform_file": InputPathType,
    "output_transform_file": str,
    "matrix": bool,
    "homogeneous_matrix": bool,
    "RAS": bool,
    "convert_to_affine_type": bool,
})
ConvertTransformFileParamsDictTagged = typing.TypedDict('ConvertTransformFileParamsDictTagged', {
    "@type": typing.Literal["ants/ConvertTransformFile"],
    "dimensions": int,
    "input_transform_file": InputPathType,
    "output_transform_file": str,
    "matrix": bool,
    "homogeneous_matrix": bool,
    "RAS": bool,
    "convert_to_affine_type": bool,
})
ConvertTransformFileParamsDict = _ConvertTransformFileParamsDictNoTag | ConvertTransformFileParamsDictTagged


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


def convert_transform_file_params(
    dimensions: int,
    input_transform_file: InputPathType,
    output_transform_file: str,
    matrix: bool = False,
    homogeneous_matrix: bool = False,
    ras: bool = False,
    convert_to_affine_type: bool = False,
) -> ConvertTransformFileParamsDictTagged:
    """
    Build parameters.
    
    Args:
        dimensions: Dimensionality of the transform file.
        input_transform_file: Path to the input transform file.
        output_transform_file: Path for the output transform file.
        matrix: Output only the transform matrix to a text file, one row per\
            line with space-delimited values. Only works for specific transform\
            types.
        homogeneous_matrix: Output an N+1 square homogeneous matrix from the\
            transform matrix and offset. Only works for specific transform types.
        ras: Convert the output into the RAS coordinate system if combined with\
            'matrix' or 'homogeneousMatrix'.
        convert_to_affine_type: Convert the input transform type to\
            AffineTransform and output again as a binary transform file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/ConvertTransformFile",
        "dimensions": dimensions,
        "input_transform_file": input_transform_file,
        "output_transform_file": output_transform_file,
        "matrix": matrix,
        "homogeneous_matrix": homogeneous_matrix,
        "RAS": ras,
        "convert_to_affine_type": convert_to_affine_type,
    }
    return params


def convert_transform_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ConvertTransformFileParamsDict` 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("dimensions", None) is None:
        raise StyxValidationError("`dimensions` must not be None")
    if not isinstance(params["dimensions"], int):
        raise StyxValidationError(f'`dimensions` has the wrong type: Received `{type(params.get("dimensions", None))}` expected `int`')
    if params.get("input_transform_file", None) is None:
        raise StyxValidationError("`input_transform_file` must not be None")
    if not isinstance(params["input_transform_file"], (pathlib.Path, str)):
        raise StyxValidationError(f'`input_transform_file` has the wrong type: Received `{type(params.get("input_transform_file", None))}` expected `InputPathType`')
    if params.get("output_transform_file", None) is None:
        raise StyxValidationError("`output_transform_file` must not be None")
    if not isinstance(params["output_transform_file"], str):
        raise StyxValidationError(f'`output_transform_file` has the wrong type: Received `{type(params.get("output_transform_file", None))}` expected `str`')
    if params.get("matrix", False) is None:
        raise StyxValidationError("`matrix` must not be None")
    if not isinstance(params["matrix"], bool):
        raise StyxValidationError(f'`matrix` has the wrong type: Received `{type(params.get("matrix", False))}` expected `bool`')
    if params.get("homogeneous_matrix", False) is None:
        raise StyxValidationError("`homogeneous_matrix` must not be None")
    if not isinstance(params["homogeneous_matrix"], bool):
        raise StyxValidationError(f'`homogeneous_matrix` has the wrong type: Received `{type(params.get("homogeneous_matrix", False))}` expected `bool`')
    if params.get("RAS", False) is None:
        raise StyxValidationError("`RAS` must not be None")
    if not isinstance(params["RAS"], bool):
        raise StyxValidationError(f'`RAS` has the wrong type: Received `{type(params.get("RAS", False))}` expected `bool`')
    if params.get("convert_to_affine_type", False) is None:
        raise StyxValidationError("`convert_to_affine_type` must not be None")
    if not isinstance(params["convert_to_affine_type"], bool):
        raise StyxValidationError(f'`convert_to_affine_type` has the wrong type: Received `{type(params.get("convert_to_affine_type", False))}` expected `bool`')


def convert_transform_file_cargs(
    params: ConvertTransformFileParamsDict,
    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("ConvertTransformFile")
    cargs.append(str(params.get("dimensions", None)))
    cargs.append(execution.input_file(params.get("input_transform_file", None)))
    cargs.append(params.get("output_transform_file", None))
    if params.get("matrix", False):
        cargs.append("--matrix")
    if params.get("homogeneous_matrix", False):
        cargs.append("--homogeneousMatrix")
    if params.get("RAS", False):
        cargs.append("--RAS")
    if params.get("convert_to_affine_type", False):
        cargs.append("--convertToAffineType")
    return cargs


def convert_transform_file_outputs(
    params: ConvertTransformFileParamsDict,
    execution: Execution,
) -> ConvertTransformFileOutputs:
    """
    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 = ConvertTransformFileOutputs(
        root=execution.output_file("."),
    )
    return ret


def convert_transform_file_execute(
    params: ConvertTransformFileParamsDict,
    runner: Runner | None = None,
) -> ConvertTransformFileOutputs:
    """
    ConvertTransformFile
    
    Utility to read in a transform file (presumed to be in binary format) and
    output it in various formats. Default output is legacy human-readable text
    format. Without any options, the output filename extension must be .txt or
    .tfm to signify a text-formatted transform file.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertTransformFileOutputs`).
    """
    convert_transform_file_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CONVERT_TRANSFORM_FILE_METADATA)
    params = execution.params(params)
    cargs = convert_transform_file_cargs(params, execution)
    ret = convert_transform_file_outputs(params, execution)
    execution.run(cargs)
    return ret


def convert_transform_file(
    dimensions: int,
    input_transform_file: InputPathType,
    output_transform_file: str,
    matrix: bool = False,
    homogeneous_matrix: bool = False,
    ras: bool = False,
    convert_to_affine_type: bool = False,
    runner: Runner | None = None,
) -> ConvertTransformFileOutputs:
    """
    ConvertTransformFile
    
    Utility to read in a transform file (presumed to be in binary format) and
    output it in various formats. Default output is legacy human-readable text
    format. Without any options, the output filename extension must be .txt or
    .tfm to signify a text-formatted transform file.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        dimensions: Dimensionality of the transform file.
        input_transform_file: Path to the input transform file.
        output_transform_file: Path for the output transform file.
        matrix: Output only the transform matrix to a text file, one row per\
            line with space-delimited values. Only works for specific transform\
            types.
        homogeneous_matrix: Output an N+1 square homogeneous matrix from the\
            transform matrix and offset. Only works for specific transform types.
        ras: Convert the output into the RAS coordinate system if combined with\
            'matrix' or 'homogeneousMatrix'.
        convert_to_affine_type: Convert the input transform type to\
            AffineTransform and output again as a binary transform file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ConvertTransformFileOutputs`).
    """
    params = convert_transform_file_params(
        dimensions=dimensions,
        input_transform_file=input_transform_file,
        output_transform_file=output_transform_file,
        matrix=matrix,
        homogeneous_matrix=homogeneous_matrix,
        ras=ras,
        convert_to_affine_type=convert_to_affine_type,
    )
    return convert_transform_file_execute(params, runner)


__all__ = [
    "CONVERT_TRANSFORM_FILE_METADATA",
    "ConvertTransformFileOutputs",
    "ConvertTransformFileParamsDict",
    "ConvertTransformFileParamsDictTagged",
    "convert_transform_file",
    "convert_transform_file_execute",
    "convert_transform_file_params",
]
