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

import typing
import pathlib
from styxdefs import *

SURFACE_APPLY_AFFINE_METADATA = Metadata(
    id="cbfa656451c57232ac09b2c71b92b95ea9448401.boutiques",
    name="surface-apply-affine",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


SurfaceApplyAffineFlirtParameters = typing.TypedDict('SurfaceApplyAffineFlirtParameters', {
    "@type": typing.NotRequired[typing.Literal["flirt"]],
    "source_volume": str,
    "target_volume": str,
})
SurfaceApplyAffineFlirtParametersTagged = typing.TypedDict('SurfaceApplyAffineFlirtParametersTagged', {
    "@type": typing.Literal["flirt"],
    "source_volume": str,
    "target_volume": str,
})


SurfaceApplyAffineParameters = typing.TypedDict('SurfaceApplyAffineParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/surface-apply-affine"]],
    "in_surf": InputPathType,
    "affine": str,
    "out_surf": str,
    "flirt": typing.NotRequired[SurfaceApplyAffineFlirtParameters | None],
})
SurfaceApplyAffineParametersTagged = typing.TypedDict('SurfaceApplyAffineParametersTagged', {
    "@type": typing.Literal["workbench/surface-apply-affine"],
    "in_surf": InputPathType,
    "affine": str,
    "out_surf": str,
    "flirt": typing.NotRequired[SurfaceApplyAffineFlirtParameters | None],
})


def surface_apply_affine_flirt_params(
    source_volume: str,
    target_volume: str,
) -> SurfaceApplyAffineFlirtParametersTagged:
    """
    Build parameters.
    
    Args:
        source_volume: the source volume used when generating the affine.
        target_volume: the target volume used when generating the affine.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "flirt",
        "source_volume": source_volume,
        "target_volume": target_volume,
    }
    return params


def surface_apply_affine_flirt_cargs(
    params: SurfaceApplyAffineFlirtParameters,
    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("-flirt")
    cargs.append(params.get("source_volume", None))
    cargs.append(params.get("target_volume", None))
    return cargs


class SurfaceApplyAffineOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceApplyAffineParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_surf: OutputPathType
    """the output transformed surface"""


def surface_apply_affine_params(
    in_surf: InputPathType,
    affine: str,
    out_surf: str,
    flirt: SurfaceApplyAffineFlirtParameters | None = None,
) -> SurfaceApplyAffineParametersTagged:
    """
    Build parameters.
    
    Args:
        in_surf: the surface to transform.
        affine: the affine file.
        out_surf: the output transformed surface.
        flirt: MUST be used if affine is a flirt affine.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-apply-affine",
        "in_surf": in_surf,
        "affine": affine,
        "out_surf": out_surf,
    }
    if flirt is not None:
        params["flirt"] = flirt
    return params


def surface_apply_affine_cargs(
    params: SurfaceApplyAffineParameters,
    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("wb_command")
    cargs.append("-surface-apply-affine")
    cargs.append(execution.input_file(params.get("in_surf", None)))
    cargs.append(params.get("affine", None))
    cargs.append(params.get("out_surf", None))
    if params.get("flirt", None) is not None:
        cargs.extend(surface_apply_affine_flirt_cargs(params.get("flirt", None), execution))
    return cargs


def surface_apply_affine_outputs(
    params: SurfaceApplyAffineParameters,
    execution: Execution,
) -> SurfaceApplyAffineOutputs:
    """
    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 = SurfaceApplyAffineOutputs(
        root=execution.output_file("."),
        out_surf=execution.output_file(params.get("out_surf", None)),
    )
    return ret


def surface_apply_affine_execute(
    params: SurfaceApplyAffineParameters,
    runner: Runner | None = None,
) -> SurfaceApplyAffineOutputs:
    """
    surface-apply-affine
    
    Apply affine transform to surface file.
    
    For flirt matrices, you must use the -flirt option, because flirt matrices
    are not a complete description of the coordinate transform they represent.
    If the -flirt option is not present, the affine must be a nifti 'world'
    affine, which can be obtained with the -convert-affine command, or aff_conv
    from the 4dfp suite.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceApplyAffineOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_APPLY_AFFINE_METADATA)
    params = execution.params(params)
    cargs = surface_apply_affine_cargs(params, execution)
    ret = surface_apply_affine_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_apply_affine(
    in_surf: InputPathType,
    affine: str,
    out_surf: str,
    flirt: SurfaceApplyAffineFlirtParameters | None = None,
    runner: Runner | None = None,
) -> SurfaceApplyAffineOutputs:
    """
    surface-apply-affine
    
    Apply affine transform to surface file.
    
    For flirt matrices, you must use the -flirt option, because flirt matrices
    are not a complete description of the coordinate transform they represent.
    If the -flirt option is not present, the affine must be a nifti 'world'
    affine, which can be obtained with the -convert-affine command, or aff_conv
    from the 4dfp suite.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        in_surf: the surface to transform.
        affine: the affine file.
        out_surf: the output transformed surface.
        flirt: MUST be used if affine is a flirt affine.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceApplyAffineOutputs`).
    """
    params = surface_apply_affine_params(
        in_surf=in_surf,
        affine=affine,
        out_surf=out_surf,
        flirt=flirt,
    )
    return surface_apply_affine_execute(params, runner)


__all__ = [
    "SURFACE_APPLY_AFFINE_METADATA",
    "SurfaceApplyAffineOutputs",
    "surface_apply_affine",
    "surface_apply_affine_execute",
    "surface_apply_affine_flirt_params",
    "surface_apply_affine_params",
]
