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

import typing
import pathlib
from styxdefs import *

SURFACE_CUT_RESAMPLE_METADATA = Metadata(
    id="4fdc0efb8ff92dfb91c639b6b9fe6d92fc4d0e35.workbench",
    name="surface-cut-resample",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceCutResampleParamsDictNoTag = typing.TypedDict('_SurfaceCutResampleParamsDictNoTag', {
    "surface-in": InputPathType,
    "current-sphere": InputPathType,
    "new-sphere": InputPathType,
    "surface-out": str,
})
SurfaceCutResampleParamsDictTagged = typing.TypedDict('SurfaceCutResampleParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-cut-resample"],
    "surface-in": InputPathType,
    "current-sphere": InputPathType,
    "new-sphere": InputPathType,
    "surface-out": str,
})
SurfaceCutResampleParamsDict = _SurfaceCutResampleParamsDictNoTag | SurfaceCutResampleParamsDictTagged


class SurfaceCutResampleOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceCutResampleParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    surface_out: OutputPathType
    """the output surface file"""


def surface_cut_resample_params(
    surface_in: InputPathType,
    current_sphere: InputPathType,
    new_sphere: InputPathType,
    surface_out: str,
) -> SurfaceCutResampleParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface_in: the surface file to resample.
        current_sphere: a sphere surface with the mesh that the input surface\
            is currently on.
        new_sphere: a sphere surface that is in register with <current-sphere>\
            and has the desired output mesh.
        surface_out: the output surface file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-cut-resample",
        "surface-in": surface_in,
        "current-sphere": current_sphere,
        "new-sphere": new_sphere,
        "surface-out": surface_out,
    }
    return params


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


def surface_cut_resample_cargs(
    params: SurfaceCutResampleParamsDict,
    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-cut-resample"
    ])
    cargs.append(execution.input_file(params.get("surface-in", None)))
    cargs.append(execution.input_file(params.get("current-sphere", None)))
    cargs.append(execution.input_file(params.get("new-sphere", None)))
    cargs.append(params.get("surface-out", None))
    return cargs


def surface_cut_resample_outputs(
    params: SurfaceCutResampleParamsDict,
    execution: Execution,
) -> SurfaceCutResampleOutputs:
    """
    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 = SurfaceCutResampleOutputs(
        root=execution.output_file("."),
        surface_out=execution.output_file(params.get("surface-out", None)),
    )
    return ret


def surface_cut_resample_execute(
    params: SurfaceCutResampleParamsDict,
    runner: Runner | None = None,
) -> SurfaceCutResampleOutputs:
    """
    RESAMPLE A CUT SURFACE.
    
    Resamples a surface file, given two spherical surfaces that are in register.
    Barycentric resampling is used, because it is usually better for resampling
    surfaces, and because it is needed to figure out the new topology anyway.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCutResampleOutputs`).
    """
    surface_cut_resample_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_CUT_RESAMPLE_METADATA)
    params = execution.params(params)
    cargs = surface_cut_resample_cargs(params, execution)
    ret = surface_cut_resample_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_cut_resample(
    surface_in: InputPathType,
    current_sphere: InputPathType,
    new_sphere: InputPathType,
    surface_out: str,
    runner: Runner | None = None,
) -> SurfaceCutResampleOutputs:
    """
    RESAMPLE A CUT SURFACE.
    
    Resamples a surface file, given two spherical surfaces that are in register.
    Barycentric resampling is used, because it is usually better for resampling
    surfaces, and because it is needed to figure out the new topology anyway.
    
    Args:
        surface_in: the surface file to resample.
        current_sphere: a sphere surface with the mesh that the input surface\
            is currently on.
        new_sphere: a sphere surface that is in register with <current-sphere>\
            and has the desired output mesh.
        surface_out: the output surface file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCutResampleOutputs`).
    """
    params = surface_cut_resample_params(
        surface_in=surface_in,
        current_sphere=current_sphere,
        new_sphere=new_sphere,
        surface_out=surface_out,
    )
    return surface_cut_resample_execute(params, runner)


__all__ = [
    "SURFACE_CUT_RESAMPLE_METADATA",
    "SurfaceCutResampleOutputs",
    "SurfaceCutResampleParamsDict",
    "SurfaceCutResampleParamsDictTagged",
    "surface_cut_resample",
    "surface_cut_resample_execute",
    "surface_cut_resample_params",
]
