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

import typing
import pathlib
from styxdefs import *

SURFACE_SMOOTHING_METADATA = Metadata(
    id="ed8f3a670c4c85072256a932d9737b524da04f12.workbench",
    name="surface-smoothing",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceSmoothingParamsDictNoTag = typing.TypedDict('_SurfaceSmoothingParamsDictNoTag', {
    "surface-in": InputPathType,
    "smoothing-strength": float,
    "smoothing-iterations": int,
    "surface-out": str,
})
SurfaceSmoothingParamsDictTagged = typing.TypedDict('SurfaceSmoothingParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-smoothing"],
    "surface-in": InputPathType,
    "smoothing-strength": float,
    "smoothing-iterations": int,
    "surface-out": str,
})
SurfaceSmoothingParamsDict = _SurfaceSmoothingParamsDictNoTag | SurfaceSmoothingParamsDictTagged


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


def surface_smoothing_params(
    surface_in: InputPathType,
    smoothing_strength: float,
    smoothing_iterations: int,
    surface_out: str,
) -> SurfaceSmoothingParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface_in: the surface file to smooth.
        smoothing_strength: smoothing strength (ranges [0.0 - 1.0]).
        smoothing_iterations: smoothing iterations.
        surface_out: output surface file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-smoothing",
        "surface-in": surface_in,
        "smoothing-strength": smoothing_strength,
        "smoothing-iterations": smoothing_iterations,
        "surface-out": surface_out,
    }
    return params


def surface_smoothing_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceSmoothingParamsDict` 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("smoothing-strength", None) is None:
        raise StyxValidationError("`smoothing-strength` must not be None")
    if not isinstance(params["smoothing-strength"], (float, int)):
        raise StyxValidationError(f'`smoothing-strength` has the wrong type: Received `{type(params.get("smoothing-strength", None))}` expected `float`')
    if params.get("smoothing-iterations", None) is None:
        raise StyxValidationError("`smoothing-iterations` must not be None")
    if not isinstance(params["smoothing-iterations"], int):
        raise StyxValidationError(f'`smoothing-iterations` has the wrong type: Received `{type(params.get("smoothing-iterations", None))}` expected `int`')
    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_smoothing_cargs(
    params: SurfaceSmoothingParamsDict,
    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-smoothing"
    ])
    cargs.append(execution.input_file(params.get("surface-in", None)))
    cargs.append(str(params.get("smoothing-strength", None)))
    cargs.append(str(params.get("smoothing-iterations", None)))
    cargs.append(params.get("surface-out", None))
    return cargs


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


def surface_smoothing_execute(
    params: SurfaceSmoothingParamsDict,
    runner: Runner | None = None,
) -> SurfaceSmoothingOutputs:
    """
    SURFACE SMOOTHING.
    
    Smooths a surface by averaging vertex coordinates with those of the
    neighboring vertices.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceSmoothingOutputs`).
    """
    surface_smoothing_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_SMOOTHING_METADATA)
    params = execution.params(params)
    cargs = surface_smoothing_cargs(params, execution)
    ret = surface_smoothing_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_smoothing(
    surface_in: InputPathType,
    smoothing_strength: float,
    smoothing_iterations: int,
    surface_out: str,
    runner: Runner | None = None,
) -> SurfaceSmoothingOutputs:
    """
    SURFACE SMOOTHING.
    
    Smooths a surface by averaging vertex coordinates with those of the
    neighboring vertices.
    
    Args:
        surface_in: the surface file to smooth.
        smoothing_strength: smoothing strength (ranges [0.0 - 1.0]).
        smoothing_iterations: smoothing iterations.
        surface_out: output surface file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceSmoothingOutputs`).
    """
    params = surface_smoothing_params(
        surface_in=surface_in,
        smoothing_strength=smoothing_strength,
        smoothing_iterations=smoothing_iterations,
        surface_out=surface_out,
    )
    return surface_smoothing_execute(params, runner)


__all__ = [
    "SURFACE_SMOOTHING_METADATA",
    "SurfaceSmoothingOutputs",
    "SurfaceSmoothingParamsDict",
    "SurfaceSmoothingParamsDictTagged",
    "surface_smoothing",
    "surface_smoothing_execute",
    "surface_smoothing_params",
]
