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

import typing
import pathlib
from styxdefs import *

SURFACE_CURVATURE_METADATA = Metadata(
    id="d5eee7e4c555970158a785c68fecd07f7b6649cb.workbench",
    name="surface-curvature",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceCurvatureMeanParamsDictNoTag = typing.TypedDict('_SurfaceCurvatureMeanParamsDictNoTag', {
    "mean-out": str,
})
SurfaceCurvatureMeanParamsDictTagged = typing.TypedDict('SurfaceCurvatureMeanParamsDictTagged', {
    "@type": typing.Literal["mean"],
    "mean-out": str,
})
SurfaceCurvatureMeanParamsDict = _SurfaceCurvatureMeanParamsDictNoTag | SurfaceCurvatureMeanParamsDictTagged


_SurfaceCurvatureGaussParamsDictNoTag = typing.TypedDict('_SurfaceCurvatureGaussParamsDictNoTag', {
    "gauss-out": str,
})
SurfaceCurvatureGaussParamsDictTagged = typing.TypedDict('SurfaceCurvatureGaussParamsDictTagged', {
    "@type": typing.Literal["gauss"],
    "gauss-out": str,
})
SurfaceCurvatureGaussParamsDict = _SurfaceCurvatureGaussParamsDictNoTag | SurfaceCurvatureGaussParamsDictTagged


_SurfaceCurvatureParamsDictNoTag = typing.TypedDict('_SurfaceCurvatureParamsDictNoTag', {
    "surface": InputPathType,
    "mean": typing.NotRequired[SurfaceCurvatureMeanParamsDict | None],
    "gauss": typing.NotRequired[SurfaceCurvatureGaussParamsDict | None],
})
SurfaceCurvatureParamsDictTagged = typing.TypedDict('SurfaceCurvatureParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-curvature"],
    "surface": InputPathType,
    "mean": typing.NotRequired[SurfaceCurvatureMeanParamsDict | None],
    "gauss": typing.NotRequired[SurfaceCurvatureGaussParamsDict | None],
})
SurfaceCurvatureParamsDict = _SurfaceCurvatureParamsDictNoTag | SurfaceCurvatureParamsDictTagged


class SurfaceCurvatureMeanOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceCurvatureMeanParamsDict | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    mean_out: OutputPathType
    """mean curvature metric"""


def surface_curvature_mean(
    mean_out: str,
) -> SurfaceCurvatureMeanParamsDictTagged:
    """
    Build parameters.
    
    Args:
        mean_out: mean curvature metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "mean",
        "mean-out": mean_out,
    }
    return params


def surface_curvature_mean_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceCurvatureMeanParamsDict` 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("mean-out", None) is None:
        raise StyxValidationError("`mean-out` must not be None")
    if not isinstance(params["mean-out"], str):
        raise StyxValidationError(f'`mean-out` has the wrong type: Received `{type(params.get("mean-out", None))}` expected `str`')


def surface_curvature_mean_cargs(
    params: SurfaceCurvatureMeanParamsDict,
    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([
        "-mean",
        params.get("mean-out", None)
    ])
    return cargs


def surface_curvature_mean_outputs(
    params: SurfaceCurvatureMeanParamsDict,
    execution: Execution,
) -> SurfaceCurvatureMeanOutputs:
    """
    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 = SurfaceCurvatureMeanOutputs(
        root=execution.output_file("."),
        mean_out=execution.output_file(params.get("mean-out", None)),
    )
    return ret


class SurfaceCurvatureGaussOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceCurvatureGaussParamsDict | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    gauss_out: OutputPathType
    """gaussian curvature metric"""


def surface_curvature_gauss(
    gauss_out: str,
) -> SurfaceCurvatureGaussParamsDictTagged:
    """
    Build parameters.
    
    Args:
        gauss_out: gaussian curvature metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "gauss",
        "gauss-out": gauss_out,
    }
    return params


def surface_curvature_gauss_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceCurvatureGaussParamsDict` 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("gauss-out", None) is None:
        raise StyxValidationError("`gauss-out` must not be None")
    if not isinstance(params["gauss-out"], str):
        raise StyxValidationError(f'`gauss-out` has the wrong type: Received `{type(params.get("gauss-out", None))}` expected `str`')


def surface_curvature_gauss_cargs(
    params: SurfaceCurvatureGaussParamsDict,
    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([
        "-gauss",
        params.get("gauss-out", None)
    ])
    return cargs


def surface_curvature_gauss_outputs(
    params: SurfaceCurvatureGaussParamsDict,
    execution: Execution,
) -> SurfaceCurvatureGaussOutputs:
    """
    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 = SurfaceCurvatureGaussOutputs(
        root=execution.output_file("."),
        gauss_out=execution.output_file(params.get("gauss-out", None)),
    )
    return ret


class SurfaceCurvatureOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceCurvatureParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    mean: SurfaceCurvatureMeanOutputs | None
    """Outputs from `surface_curvature_mean_outputs`."""
    gauss: SurfaceCurvatureGaussOutputs | None
    """Outputs from `surface_curvature_gauss_outputs`."""


def surface_curvature_params(
    surface: InputPathType,
    mean: SurfaceCurvatureMeanParamsDict | None = None,
    gauss: SurfaceCurvatureGaussParamsDict | None = None,
) -> SurfaceCurvatureParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the surface to compute the curvature of.
        mean: output mean curvature.
        gauss: output gaussian curvature.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-curvature",
        "surface": surface,
    }
    if mean is not None:
        params["mean"] = mean
    if gauss is not None:
        params["gauss"] = gauss
    return params


def surface_curvature_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceCurvatureParamsDict` 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("mean", None) is not None:
        surface_curvature_mean_validate(params["mean"])
    if params.get("gauss", None) is not None:
        surface_curvature_gauss_validate(params["gauss"])


def surface_curvature_cargs(
    params: SurfaceCurvatureParamsDict,
    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-curvature"
    ])
    cargs.append(execution.input_file(params.get("surface", None)))
    if params.get("mean", None) is not None or params.get("gauss", None) is not None:
        cargs.extend([
            *(surface_curvature_mean_cargs(params.get("mean", None), execution) if (params.get("mean", None) is not None) else []),
            *(surface_curvature_gauss_cargs(params.get("gauss", None), execution) if (params.get("gauss", None) is not None) else [])
        ])
    return cargs


def surface_curvature_outputs(
    params: SurfaceCurvatureParamsDict,
    execution: Execution,
) -> SurfaceCurvatureOutputs:
    """
    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 = SurfaceCurvatureOutputs(
        root=execution.output_file("."),
        mean=surface_curvature_mean_outputs(params.get("mean"), execution) if params.get("mean") else None,
        gauss=surface_curvature_gauss_outputs(params.get("gauss"), execution) if params.get("gauss") else None,
    )
    return ret


def surface_curvature_execute(
    params: SurfaceCurvatureParamsDict,
    runner: Runner | None = None,
) -> SurfaceCurvatureOutputs:
    """
    CALCULATE CURVATURE OF SURFACE.
    
    Compute the curvature of the surface, using the method from:
    Interactive Texture Mapping by J. Maillot, Yahia, and Verroust, 1993.
    ACM-0-98791-601-8/93/008.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCurvatureOutputs`).
    """
    surface_curvature_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_CURVATURE_METADATA)
    params = execution.params(params)
    cargs = surface_curvature_cargs(params, execution)
    ret = surface_curvature_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_curvature(
    surface: InputPathType,
    mean: SurfaceCurvatureMeanParamsDict | None = None,
    gauss: SurfaceCurvatureGaussParamsDict | None = None,
    runner: Runner | None = None,
) -> SurfaceCurvatureOutputs:
    """
    CALCULATE CURVATURE OF SURFACE.
    
    Compute the curvature of the surface, using the method from:
    Interactive Texture Mapping by J. Maillot, Yahia, and Verroust, 1993.
    ACM-0-98791-601-8/93/008.
    
    Args:
        surface: the surface to compute the curvature of.
        mean: output mean curvature.
        gauss: output gaussian curvature.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCurvatureOutputs`).
    """
    params = surface_curvature_params(
        surface=surface,
        mean=mean,
        gauss=gauss,
    )
    return surface_curvature_execute(params, runner)


__all__ = [
    "SURFACE_CURVATURE_METADATA",
    "SurfaceCurvatureGaussOutputs",
    "SurfaceCurvatureGaussParamsDict",
    "SurfaceCurvatureGaussParamsDictTagged",
    "SurfaceCurvatureMeanOutputs",
    "SurfaceCurvatureMeanParamsDict",
    "SurfaceCurvatureMeanParamsDictTagged",
    "SurfaceCurvatureOutputs",
    "SurfaceCurvatureParamsDict",
    "SurfaceCurvatureParamsDictTagged",
    "surface_curvature",
    "surface_curvature_execute",
    "surface_curvature_gauss",
    "surface_curvature_mean",
    "surface_curvature_params",
]
