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

import typing
import pathlib
from styxdefs import *

SURFACE_FLIP_NORMALS_METADATA = Metadata(
    id="bd50d144fdc0e871fae85f49e492aee6de124549.workbench",
    name="surface-flip-normals",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceFlipNormalsParamsDictNoTag = typing.TypedDict('_SurfaceFlipNormalsParamsDictNoTag', {
    "surface": InputPathType,
    "surface-out": str,
})
SurfaceFlipNormalsParamsDictTagged = typing.TypedDict('SurfaceFlipNormalsParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-flip-normals"],
    "surface": InputPathType,
    "surface-out": str,
})
SurfaceFlipNormalsParamsDict = _SurfaceFlipNormalsParamsDictNoTag | SurfaceFlipNormalsParamsDictTagged


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


def surface_flip_normals_params(
    surface: InputPathType,
    surface_out: str,
) -> SurfaceFlipNormalsParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the surface to flip the normals of.
        surface_out: the output surface.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-flip-normals",
        "surface": surface,
        "surface-out": surface_out,
    }
    return params


def surface_flip_normals_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceFlipNormalsParamsDict` 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", None) is None:
        raise StyxValidationError("`surface` must not be None")
    if not isinstance(params["surface"], (pathlib.Path, str)):
        raise StyxValidationError(f'`surface` has the wrong type: Received `{type(params.get("surface", 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_flip_normals_cargs(
    params: SurfaceFlipNormalsParamsDict,
    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-flip-normals"
    ])
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(params.get("surface-out", None))
    return cargs


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


def surface_flip_normals_execute(
    params: SurfaceFlipNormalsParamsDict,
    runner: Runner | None = None,
) -> SurfaceFlipNormalsOutputs:
    """
    FLIP ALL TILES ON A SURFACE.
    
    Flips all triangles on a surface, resulting in surface normals being flipped
    the other direction (inward vs outward). If you transform a surface with an
    affine that has negative determinant, or a warpfield that similarly flips
    the surface, you may end up with a surface that has normals pointing
    inwards, which may have display problems. Using this command will solve that
    problem.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceFlipNormalsOutputs`).
    """
    surface_flip_normals_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_FLIP_NORMALS_METADATA)
    params = execution.params(params)
    cargs = surface_flip_normals_cargs(params, execution)
    ret = surface_flip_normals_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_flip_normals(
    surface: InputPathType,
    surface_out: str,
    runner: Runner | None = None,
) -> SurfaceFlipNormalsOutputs:
    """
    FLIP ALL TILES ON A SURFACE.
    
    Flips all triangles on a surface, resulting in surface normals being flipped
    the other direction (inward vs outward). If you transform a surface with an
    affine that has negative determinant, or a warpfield that similarly flips
    the surface, you may end up with a surface that has normals pointing
    inwards, which may have display problems. Using this command will solve that
    problem.
    
    Args:
        surface: the surface to flip the normals of.
        surface_out: the output surface.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceFlipNormalsOutputs`).
    """
    params = surface_flip_normals_params(
        surface=surface,
        surface_out=surface_out,
    )
    return surface_flip_normals_execute(params, runner)


__all__ = [
    "SURFACE_FLIP_NORMALS_METADATA",
    "SurfaceFlipNormalsOutputs",
    "SurfaceFlipNormalsParamsDict",
    "SurfaceFlipNormalsParamsDictTagged",
    "surface_flip_normals",
    "surface_flip_normals_execute",
    "surface_flip_normals_params",
]
