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

import typing
import pathlib
from styxdefs import *

SURFACE_TO_SURFACE_3D_DISTANCE_METADATA = Metadata(
    id="8c740646d34e5a61db7e9f5f4bf71bcd927fb141.workbench",
    name="surface-to-surface-3d-distance",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceToSurface3dDistanceVectorsParamsDictNoTag = typing.TypedDict('_SurfaceToSurface3dDistanceVectorsParamsDictNoTag', {
    "vectors-out": str,
})
SurfaceToSurface3dDistanceVectorsParamsDictTagged = typing.TypedDict('SurfaceToSurface3dDistanceVectorsParamsDictTagged', {
    "@type": typing.Literal["vectors"],
    "vectors-out": str,
})
SurfaceToSurface3dDistanceVectorsParamsDict = _SurfaceToSurface3dDistanceVectorsParamsDictNoTag | SurfaceToSurface3dDistanceVectorsParamsDictTagged


_SurfaceToSurface3dDistanceParamsDictNoTag = typing.TypedDict('_SurfaceToSurface3dDistanceParamsDictNoTag', {
    "surface-comp": InputPathType,
    "surface-ref": InputPathType,
    "dists-out": str,
    "vectors": typing.NotRequired[SurfaceToSurface3dDistanceVectorsParamsDict | None],
})
SurfaceToSurface3dDistanceParamsDictTagged = typing.TypedDict('SurfaceToSurface3dDistanceParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-to-surface-3d-distance"],
    "surface-comp": InputPathType,
    "surface-ref": InputPathType,
    "dists-out": str,
    "vectors": typing.NotRequired[SurfaceToSurface3dDistanceVectorsParamsDict | None],
})
SurfaceToSurface3dDistanceParamsDict = _SurfaceToSurface3dDistanceParamsDictNoTag | SurfaceToSurface3dDistanceParamsDictTagged


class SurfaceToSurface3dDistanceVectorsOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceToSurface3dDistanceVectorsParamsDict | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    vectors_out: OutputPathType
    """the output vectors"""


def surface_to_surface_3d_distance_vectors(
    vectors_out: str,
) -> SurfaceToSurface3dDistanceVectorsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        vectors_out: the output vectors.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "vectors",
        "vectors-out": vectors_out,
    }
    return params


def surface_to_surface_3d_distance_vectors_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceToSurface3dDistanceVectorsParamsDict` 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("vectors-out", None) is None:
        raise StyxValidationError("`vectors-out` must not be None")
    if not isinstance(params["vectors-out"], str):
        raise StyxValidationError(f'`vectors-out` has the wrong type: Received `{type(params.get("vectors-out", None))}` expected `str`')


def surface_to_surface_3d_distance_vectors_cargs(
    params: SurfaceToSurface3dDistanceVectorsParamsDict,
    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.extend([
        "-vectors",
        params.get("vectors-out", None)
    ])
    return cargs


def surface_to_surface_3d_distance_vectors_outputs(
    params: SurfaceToSurface3dDistanceVectorsParamsDict,
    execution: Execution,
) -> SurfaceToSurface3dDistanceVectorsOutputs:
    """
    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 = SurfaceToSurface3dDistanceVectorsOutputs(
        root=execution.output_file("."),
        vectors_out=execution.output_file(params.get("vectors-out", None)),
    )
    return ret


class SurfaceToSurface3dDistanceOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceToSurface3dDistanceParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    dists_out: OutputPathType
    """the output distances"""
    vectors: SurfaceToSurface3dDistanceVectorsOutputs | None
    """Outputs from `surface_to_surface_3d_distance_vectors_outputs`."""


def surface_to_surface_3d_distance_params(
    surface_comp: InputPathType,
    surface_ref: InputPathType,
    dists_out: str,
    vectors: SurfaceToSurface3dDistanceVectorsParamsDict | None = None,
) -> SurfaceToSurface3dDistanceParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface_comp: the surface to compare to the reference.
        surface_ref: the surface to use as the reference.
        dists_out: the output distances.
        vectors: output the displacement vectors.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-to-surface-3d-distance",
        "surface-comp": surface_comp,
        "surface-ref": surface_ref,
        "dists-out": dists_out,
    }
    if vectors is not None:
        params["vectors"] = vectors
    return params


def surface_to_surface_3d_distance_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceToSurface3dDistanceParamsDict` 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("surface-comp", None) is None:
        raise StyxValidationError("`surface-comp` must not be None")
    if not isinstance(params["surface-comp"], (pathlib.Path, str)):
        raise StyxValidationError(f'`surface-comp` has the wrong type: Received `{type(params.get("surface-comp", None))}` expected `InputPathType`')
    if params.get("surface-ref", None) is None:
        raise StyxValidationError("`surface-ref` must not be None")
    if not isinstance(params["surface-ref"], (pathlib.Path, str)):
        raise StyxValidationError(f'`surface-ref` has the wrong type: Received `{type(params.get("surface-ref", None))}` expected `InputPathType`')
    if params.get("dists-out", None) is None:
        raise StyxValidationError("`dists-out` must not be None")
    if not isinstance(params["dists-out"], str):
        raise StyxValidationError(f'`dists-out` has the wrong type: Received `{type(params.get("dists-out", None))}` expected `str`')
    if params.get("vectors", None) is not None:
        surface_to_surface_3d_distance_vectors_validate(params["vectors"])


def surface_to_surface_3d_distance_cargs(
    params: SurfaceToSurface3dDistanceParamsDict,
    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.extend([
        "wb_command",
        "-surface-to-surface-3d-distance"
    ])
    cargs.append(execution.input_file(params.get("surface-comp", None)))
    cargs.append(execution.input_file(params.get("surface-ref", None)))
    cargs.append(params.get("dists-out", None))
    if params.get("vectors", None) is not None:
        cargs.extend(surface_to_surface_3d_distance_vectors_cargs(params.get("vectors", None), execution))
    return cargs


def surface_to_surface_3d_distance_outputs(
    params: SurfaceToSurface3dDistanceParamsDict,
    execution: Execution,
) -> SurfaceToSurface3dDistanceOutputs:
    """
    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 = SurfaceToSurface3dDistanceOutputs(
        root=execution.output_file("."),
        dists_out=execution.output_file(params.get("dists-out", None)),
        vectors=surface_to_surface_3d_distance_vectors_outputs(params.get("vectors"), execution) if params.get("vectors") else None,
    )
    return ret


def surface_to_surface_3d_distance_execute(
    params: SurfaceToSurface3dDistanceParamsDict,
    runner: Runner | None = None,
) -> SurfaceToSurface3dDistanceOutputs:
    """
    COMPUTE DISTANCE BETWEEN CORRESPONDING VERTICES.
    
    Computes the vector difference between the vertices of each surface with the
    same index, as (comp - ref), and output the magnitudes, and optionally the
    displacement vectors.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceToSurface3dDistanceOutputs`).
    """
    surface_to_surface_3d_distance_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_TO_SURFACE_3D_DISTANCE_METADATA)
    params = execution.params(params)
    cargs = surface_to_surface_3d_distance_cargs(params, execution)
    ret = surface_to_surface_3d_distance_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_to_surface_3d_distance(
    surface_comp: InputPathType,
    surface_ref: InputPathType,
    dists_out: str,
    vectors: SurfaceToSurface3dDistanceVectorsParamsDict | None = None,
    runner: Runner | None = None,
) -> SurfaceToSurface3dDistanceOutputs:
    """
    COMPUTE DISTANCE BETWEEN CORRESPONDING VERTICES.
    
    Computes the vector difference between the vertices of each surface with the
    same index, as (comp - ref), and output the magnitudes, and optionally the
    displacement vectors.
    
    Args:
        surface_comp: the surface to compare to the reference.
        surface_ref: the surface to use as the reference.
        dists_out: the output distances.
        vectors: output the displacement vectors.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceToSurface3dDistanceOutputs`).
    """
    params = surface_to_surface_3d_distance_params(
        surface_comp=surface_comp,
        surface_ref=surface_ref,
        dists_out=dists_out,
        vectors=vectors,
    )
    return surface_to_surface_3d_distance_execute(params, runner)


__all__ = [
    "SURFACE_TO_SURFACE_3D_DISTANCE_METADATA",
    "SurfaceToSurface3dDistanceOutputs",
    "SurfaceToSurface3dDistanceParamsDict",
    "SurfaceToSurface3dDistanceParamsDictTagged",
    "SurfaceToSurface3dDistanceVectorsOutputs",
    "SurfaceToSurface3dDistanceVectorsParamsDict",
    "SurfaceToSurface3dDistanceVectorsParamsDictTagged",
    "surface_to_surface_3d_distance",
    "surface_to_surface_3d_distance_execute",
    "surface_to_surface_3d_distance_params",
    "surface_to_surface_3d_distance_vectors",
]
