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

import typing
import pathlib
from styxdefs import *

ANTSINTEGRATE_VECTOR_FIELD_METADATA = Metadata(
    id="834181e3e327a31ccc73d56b821e216f4579fc76.boutiques",
    name="ANTSIntegrateVectorField",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_AntsintegrateVectorFieldParamsDictNoTag = typing.TypedDict('_AntsintegrateVectorFieldParamsDictNoTag', {
    "vector_field_input": InputPathType,
    "roi_mask_input": InputPathType,
    "fibers_output": str,
    "length_image_output": str,
})
AntsintegrateVectorFieldParamsDictTagged = typing.TypedDict('AntsintegrateVectorFieldParamsDictTagged', {
    "@type": typing.Literal["ants/ANTSIntegrateVectorField"],
    "vector_field_input": InputPathType,
    "roi_mask_input": InputPathType,
    "fibers_output": str,
    "length_image_output": str,
})
AntsintegrateVectorFieldParamsDict = _AntsintegrateVectorFieldParamsDictNoTag | AntsintegrateVectorFieldParamsDictTagged


class AntsintegrateVectorFieldOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AntsintegrateVectorFieldParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    fibers_out_vtk: OutputPathType
    """The output is the fibers as a VTK text file."""
    length_image_out_nii: OutputPathType
    """The output is the length image."""


def antsintegrate_vector_field_params(
    vector_field_input: InputPathType,
    roi_mask_input: InputPathType,
    fibers_output: str,
    length_image_output: str,
) -> AntsintegrateVectorFieldParamsDictTagged:
    """
    Build parameters.
    
    Args:
        vector_field_input: Input vector field image (e.g., VecImageIN.nii.gz),\
            where vectors are voxels.
        roi_mask_input: Input ROI mask image (e.g., ROIMaskIN.nii.gz), an\
            integer image controlling where the integration is performed.
        fibers_output: Output VTK text file for fibers (e.g., FibersOUT.vtk).
        length_image_output: Output length image (e.g., LengthImageOUT.nii.gz).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/ANTSIntegrateVectorField",
        "vector_field_input": vector_field_input,
        "roi_mask_input": roi_mask_input,
        "fibers_output": fibers_output,
        "length_image_output": length_image_output,
    }
    return params


def antsintegrate_vector_field_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AntsintegrateVectorFieldParamsDict` 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("vector_field_input", None) is None:
        raise StyxValidationError("`vector_field_input` must not be None")
    if not isinstance(params["vector_field_input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`vector_field_input` has the wrong type: Received `{type(params.get("vector_field_input", None))}` expected `InputPathType`')
    if params.get("roi_mask_input", None) is None:
        raise StyxValidationError("`roi_mask_input` must not be None")
    if not isinstance(params["roi_mask_input"], (pathlib.Path, str)):
        raise StyxValidationError(f'`roi_mask_input` has the wrong type: Received `{type(params.get("roi_mask_input", None))}` expected `InputPathType`')
    if params.get("fibers_output", None) is None:
        raise StyxValidationError("`fibers_output` must not be None")
    if not isinstance(params["fibers_output"], str):
        raise StyxValidationError(f'`fibers_output` has the wrong type: Received `{type(params.get("fibers_output", None))}` expected `str`')
    if params.get("length_image_output", None) is None:
        raise StyxValidationError("`length_image_output` must not be None")
    if not isinstance(params["length_image_output"], str):
        raise StyxValidationError(f'`length_image_output` has the wrong type: Received `{type(params.get("length_image_output", None))}` expected `str`')


def antsintegrate_vector_field_cargs(
    params: AntsintegrateVectorFieldParamsDict,
    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("ANTSIntegrateVectorField")
    cargs.append(execution.input_file(params.get("vector_field_input", None)))
    cargs.append(execution.input_file(params.get("roi_mask_input", None)))
    cargs.append(params.get("fibers_output", None))
    cargs.append(params.get("length_image_output", None))
    return cargs


def antsintegrate_vector_field_outputs(
    params: AntsintegrateVectorFieldParamsDict,
    execution: Execution,
) -> AntsintegrateVectorFieldOutputs:
    """
    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 = AntsintegrateVectorFieldOutputs(
        root=execution.output_file("."),
        fibers_out_vtk=execution.output_file(params.get("fibers_output", None)),
        length_image_out_nii=execution.output_file(params.get("length_image_output", None)),
    )
    return ret


def antsintegrate_vector_field_execute(
    params: AntsintegrateVectorFieldParamsDict,
    runner: Runner | None = None,
) -> AntsintegrateVectorFieldOutputs:
    """
    ANTSIntegrateVectorField
    
    This tool integrates a vector field, where vectors are voxels, using a
    region of interest (ROI) mask. The ROI mask controls where the integration
    is performed and specifies the starting point region.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsintegrateVectorFieldOutputs`).
    """
    antsintegrate_vector_field_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANTSINTEGRATE_VECTOR_FIELD_METADATA)
    params = execution.params(params)
    cargs = antsintegrate_vector_field_cargs(params, execution)
    ret = antsintegrate_vector_field_outputs(params, execution)
    execution.run(cargs)
    return ret


def antsintegrate_vector_field(
    vector_field_input: InputPathType,
    roi_mask_input: InputPathType,
    fibers_output: str,
    length_image_output: str,
    runner: Runner | None = None,
) -> AntsintegrateVectorFieldOutputs:
    """
    ANTSIntegrateVectorField
    
    This tool integrates a vector field, where vectors are voxels, using a
    region of interest (ROI) mask. The ROI mask controls where the integration
    is performed and specifies the starting point region.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        vector_field_input: Input vector field image (e.g., VecImageIN.nii.gz),\
            where vectors are voxels.
        roi_mask_input: Input ROI mask image (e.g., ROIMaskIN.nii.gz), an\
            integer image controlling where the integration is performed.
        fibers_output: Output VTK text file for fibers (e.g., FibersOUT.vtk).
        length_image_output: Output length image (e.g., LengthImageOUT.nii.gz).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AntsintegrateVectorFieldOutputs`).
    """
    params = antsintegrate_vector_field_params(
        vector_field_input=vector_field_input,
        roi_mask_input=roi_mask_input,
        fibers_output=fibers_output,
        length_image_output=length_image_output,
    )
    return antsintegrate_vector_field_execute(params, runner)


__all__ = [
    "ANTSINTEGRATE_VECTOR_FIELD_METADATA",
    "AntsintegrateVectorFieldOutputs",
    "AntsintegrateVectorFieldParamsDict",
    "AntsintegrateVectorFieldParamsDictTagged",
    "antsintegrate_vector_field",
    "antsintegrate_vector_field_execute",
    "antsintegrate_vector_field_params",
]
