# 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="a7b40c2eabbd684e2841e97eb61c046f68f16b83.workbench",
    name="annotation-resample",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_AnnotationResampleSurfacePairParamsDictNoTag = typing.TypedDict('_AnnotationResampleSurfacePairParamsDictNoTag', {
    "source-surface": InputPathType,
    "target-surface": InputPathType,
})
AnnotationResampleSurfacePairParamsDictTagged = typing.TypedDict('AnnotationResampleSurfacePairParamsDictTagged', {
    "@type": typing.Literal["surface-pair"],
    "source-surface": InputPathType,
    "target-surface": InputPathType,
})
AnnotationResampleSurfacePairParamsDict = _AnnotationResampleSurfacePairParamsDictNoTag | AnnotationResampleSurfacePairParamsDictTagged


_AnnotationResampleParamsDictNoTag = typing.TypedDict('_AnnotationResampleParamsDictNoTag', {
    "annotation-in": InputPathType,
    "annotation-out": str,
    "surface-pair": typing.NotRequired[list[AnnotationResampleSurfacePairParamsDict] | None],
})
AnnotationResampleParamsDictTagged = typing.TypedDict('AnnotationResampleParamsDictTagged', {
    "@type": typing.Literal["workbench/annotation-resample"],
    "annotation-in": InputPathType,
    "annotation-out": str,
    "surface-pair": typing.NotRequired[list[AnnotationResampleSurfacePairParamsDict] | None],
})
AnnotationResampleParamsDict = _AnnotationResampleParamsDictNoTag | AnnotationResampleParamsDictTagged


def annotation_resample_surface_pair(
    source_surface: InputPathType,
    target_surface: InputPathType,
) -> AnnotationResampleSurfacePairParamsDictTagged:
    """
    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_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AnnotationResampleSurfacePairParamsDict` 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("source-surface", None) is None:
        raise StyxValidationError("`source-surface` must not be None")
    if not isinstance(params["source-surface"], (pathlib.Path, str)):
        raise StyxValidationError(f'`source-surface` has the wrong type: Received `{type(params.get("source-surface", None))}` expected `InputPathType`')
    if params.get("target-surface", None) is None:
        raise StyxValidationError("`target-surface` must not be None")
    if not isinstance(params["target-surface"], (pathlib.Path, str)):
        raise StyxValidationError(f'`target-surface` has the wrong type: Received `{type(params.get("target-surface", None))}` expected `InputPathType`')


def annotation_resample_surface_pair_cargs(
    params: AnnotationResampleSurfacePairParamsDict,
    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([
        "-surface-pair",
        execution.input_file(params.get("source-surface", None)),
        execution.input_file(params.get("target-surface", None))
    ])
    return cargs


class AnnotationResampleOutputs(typing.NamedTuple):
    """
    Output object returned when calling `AnnotationResampleParamsDict(...)`.
    """
    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[AnnotationResampleSurfacePairParamsDict] | None = None,
) -> AnnotationResampleParamsDictTagged:
    """
    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_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `AnnotationResampleParamsDict` 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("annotation-in", None) is None:
        raise StyxValidationError("`annotation-in` must not be None")
    if not isinstance(params["annotation-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`annotation-in` has the wrong type: Received `{type(params.get("annotation-in", None))}` expected `InputPathType`')
    if params.get("annotation-out", None) is None:
        raise StyxValidationError("`annotation-out` must not be None")
    if not isinstance(params["annotation-out"], str):
        raise StyxValidationError(f'`annotation-out` has the wrong type: Received `{type(params.get("annotation-out", None))}` expected `str`')
    if params.get("surface-pair", None) is not None:
        if not isinstance(params["surface-pair"], list):
            raise StyxValidationError(f'`surface-pair` has the wrong type: Received `{type(params.get("surface-pair", None))}` expected `list[AnnotationResampleSurfacePairParamsDict] | None`')
        for e in params["surface-pair"]:
            annotation_resample_surface_pair_validate(e)


def annotation_resample_cargs(
    params: AnnotationResampleParamsDict,
    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",
        "-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: AnnotationResampleParamsDict,
    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: AnnotationResampleParamsDict,
    runner: Runner | None = None,
) -> AnnotationResampleOutputs:
    """
    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.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `AnnotationResampleOutputs`).
    """
    annotation_resample_validate(params)
    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[AnnotationResampleSurfacePairParamsDict] | None = None,
    runner: Runner | None = None,
) -> AnnotationResampleOutputs:
    """
    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.
    
    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",
    "AnnotationResampleParamsDict",
    "AnnotationResampleParamsDictTagged",
    "AnnotationResampleSurfacePairParamsDict",
    "AnnotationResampleSurfacePairParamsDictTagged",
    "annotation_resample",
    "annotation_resample_execute",
    "annotation_resample_params",
    "annotation_resample_surface_pair",
]
