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

import typing
import pathlib
from styxdefs import *

ANNOTATION_RESAMPLE_METADATA = Metadata(
    id="d27a061127258ae972e19d738c9377d395c2db20.boutiques",
    name="annotation-resample",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


AnnotationResampleSurfacePairParameters = typing.TypedDict('AnnotationResampleSurfacePairParameters', {
    "@type": typing.NotRequired[typing.Literal["surface_pair"]],
    "source_surface": InputPathType,
    "target_surface": InputPathType,
})
AnnotationResampleSurfacePairParametersTagged = typing.TypedDict('AnnotationResampleSurfacePairParametersTagged', {
    "@type": typing.Literal["surface_pair"],
    "source_surface": InputPathType,
    "target_surface": InputPathType,
})


AnnotationResampleParameters = typing.TypedDict('AnnotationResampleParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/annotation-resample"]],
    "annotation_in": InputPathType,
    "annotation_out": str,
    "surface_pair": typing.NotRequired[list[AnnotationResampleSurfacePairParameters] | None],
})
AnnotationResampleParametersTagged = typing.TypedDict('AnnotationResampleParametersTagged', {
    "@type": typing.Literal["workbench/annotation-resample"],
    "annotation_in": InputPathType,
    "annotation_out": str,
    "surface_pair": typing.NotRequired[list[AnnotationResampleSurfacePairParameters] | None],
})


def annotation_resample_surface_pair_params(
    source_surface: InputPathType,
    target_surface: InputPathType,
) -> AnnotationResampleSurfacePairParametersTagged:
    """
    Build parameters.
    
    Args:
        source_surface: the midthickness surface of the current mesh the\
            annotations use.
        target_surface: the midthickness surface of the mesh the annotations\
            should be transferred to.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "surface_pair",
        "source_surface": source_surface,
        "target_surface": target_surface,
    }
    return params


def annotation_resample_surface_pair_cargs(
    params: AnnotationResampleSurfacePairParameters,
    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("-surface-pair")
    cargs.append(execution.input_file(params.get("source_surface", None)))
    cargs.append(execution.input_file(params.get("target_surface", None)))
    return cargs


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


def annotation_resample_params(
    annotation_in: InputPathType,
    annotation_out: str,
    surface_pair: list[AnnotationResampleSurfacePairParameters] | None = None,
) -> AnnotationResampleParametersTagged:
    """
    Build parameters.
    
    Args:
        annotation_in: the annotation file to resample.
        annotation_out: name of resampled annotation file.
        surface_pair: pair of surfaces for resampling surface annotations for\
            one structure.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/annotation-resample",
        "annotation_in": annotation_in,
        "annotation_out": annotation_out,
    }
    if surface_pair is not None:
        params["surface_pair"] = surface_pair
    return params


def annotation_resample_cargs(
    params: AnnotationResampleParameters,
    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("-annotation-resample")
    cargs.append(execution.input_file(params.get("annotation_in", None)))
    cargs.append(params.get("annotation_out", None))
    if params.get("surface_pair", None) is not None:
        cargs.extend([a for c in [annotation_resample_surface_pair_cargs(s, execution) for s in params.get("surface_pair", None)] for a in c])
    return cargs


def annotation_resample_outputs(
    params: AnnotationResampleParameters,
    execution: Execution,
) -> AnnotationResampleOutputs:
    """
    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 = AnnotationResampleOutputs(
        root=execution.output_file("."),
    )
    return ret


def annotation_resample_execute(
    params: AnnotationResampleParameters,
    runner: Runner | None = None,
) -> AnnotationResampleOutputs:
    """
    annotation-resample
    
    Resample an annotation file to different meshes.
    
    Resample an annotation file from the source mesh to the target mesh.
    
    Only annotations in surface space are modified, no changes are made to
    annotations in other spaces. The -surface-pair option may be repeated for
    additional structures used by surface space annotations.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AnnotationResampleOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(ANNOTATION_RESAMPLE_METADATA)
    params = execution.params(params)
    cargs = annotation_resample_cargs(params, execution)
    ret = annotation_resample_outputs(params, execution)
    execution.run(cargs)
    return ret


def annotation_resample(
    annotation_in: InputPathType,
    annotation_out: str,
    surface_pair: list[AnnotationResampleSurfacePairParameters] | None = None,
    runner: Runner | None = None,
) -> AnnotationResampleOutputs:
    """
    annotation-resample
    
    Resample an annotation file to different meshes.
    
    Resample an annotation file from the source mesh to the target mesh.
    
    Only annotations in surface space are modified, no changes are made to
    annotations in other spaces. The -surface-pair option may be repeated for
    additional structures used by surface space annotations.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        annotation_in: the annotation file to resample.
        annotation_out: name of resampled annotation file.
        surface_pair: pair of surfaces for resampling surface annotations for\
            one structure.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AnnotationResampleOutputs`).
    """
    params = annotation_resample_params(
        annotation_in=annotation_in,
        annotation_out=annotation_out,
        surface_pair=surface_pair,
    )
    return annotation_resample_execute(params, runner)


__all__ = [
    "ANNOTATION_RESAMPLE_METADATA",
    "AnnotationResampleOutputs",
    "annotation_resample",
    "annotation_resample_execute",
    "annotation_resample_params",
    "annotation_resample_surface_pair_params",
]
