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

import typing
import pathlib
from styxdefs import *

SURFACE_MODIFY_SPHERE_METADATA = Metadata(
    id="bd702111cb8b1766b63c379235de453d7fec39d5.workbench",
    name="surface-modify-sphere",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceModifySphereParamsDictNoTag = typing.TypedDict('_SurfaceModifySphereParamsDictNoTag', {
    "sphere-in": InputPathType,
    "radius": float,
    "sphere-out": str,
    "recenter": bool,
})
SurfaceModifySphereParamsDictTagged = typing.TypedDict('SurfaceModifySphereParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-modify-sphere"],
    "sphere-in": InputPathType,
    "radius": float,
    "sphere-out": str,
    "recenter": bool,
})
SurfaceModifySphereParamsDict = _SurfaceModifySphereParamsDictNoTag | SurfaceModifySphereParamsDictTagged


class SurfaceModifySphereOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceModifySphereParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    sphere_out: OutputPathType
    """the output sphere"""


def surface_modify_sphere_params(
    sphere_in: InputPathType,
    radius: float,
    sphere_out: str,
    recenter: bool = False,
) -> SurfaceModifySphereParamsDictTagged:
    """
    Build parameters.
    
    Args:
        sphere_in: the sphere to modify.
        radius: the radius the output sphere should have.
        sphere_out: the output sphere.
        recenter: recenter the sphere by means of the bounding box.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-modify-sphere",
        "sphere-in": sphere_in,
        "radius": radius,
        "sphere-out": sphere_out,
        "recenter": recenter,
    }
    return params


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


def surface_modify_sphere_cargs(
    params: SurfaceModifySphereParamsDict,
    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-modify-sphere"
    ])
    cargs.append(execution.input_file(params.get("sphere-in", None)))
    cargs.append(str(params.get("radius", None)))
    cargs.append(params.get("sphere-out", None))
    if params.get("recenter", False):
        cargs.append("-recenter")
    return cargs


def surface_modify_sphere_outputs(
    params: SurfaceModifySphereParamsDict,
    execution: Execution,
) -> SurfaceModifySphereOutputs:
    """
    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 = SurfaceModifySphereOutputs(
        root=execution.output_file("."),
        sphere_out=execution.output_file(params.get("sphere-out", None)),
    )
    return ret


def surface_modify_sphere_execute(
    params: SurfaceModifySphereParamsDict,
    runner: Runner | None = None,
) -> SurfaceModifySphereOutputs:
    """
    CHANGE RADIUS AND OPTIONALLY RECENTER A SPHERE.
    
    This command may be useful if you have used -surface-resample to resample a
    sphere, which can suffer from problems generally not present in
    -surface-sphere-project-unproject. If the sphere should already be centered
    around the origin, using -recenter may still shift it slightly before
    changing the radius, which is likely to be undesireable.
    
    If <sphere-in> is not close to spherical, or not centered around the origin
    and -recenter is not used, a warning is printed.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceModifySphereOutputs`).
    """
    surface_modify_sphere_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_MODIFY_SPHERE_METADATA)
    params = execution.params(params)
    cargs = surface_modify_sphere_cargs(params, execution)
    ret = surface_modify_sphere_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_modify_sphere(
    sphere_in: InputPathType,
    radius: float,
    sphere_out: str,
    recenter: bool = False,
    runner: Runner | None = None,
) -> SurfaceModifySphereOutputs:
    """
    CHANGE RADIUS AND OPTIONALLY RECENTER A SPHERE.
    
    This command may be useful if you have used -surface-resample to resample a
    sphere, which can suffer from problems generally not present in
    -surface-sphere-project-unproject. If the sphere should already be centered
    around the origin, using -recenter may still shift it slightly before
    changing the radius, which is likely to be undesireable.
    
    If <sphere-in> is not close to spherical, or not centered around the origin
    and -recenter is not used, a warning is printed.
    
    Args:
        sphere_in: the sphere to modify.
        radius: the radius the output sphere should have.
        sphere_out: the output sphere.
        recenter: recenter the sphere by means of the bounding box.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceModifySphereOutputs`).
    """
    params = surface_modify_sphere_params(
        sphere_in=sphere_in,
        radius=radius,
        sphere_out=sphere_out,
        recenter=recenter,
    )
    return surface_modify_sphere_execute(params, runner)


__all__ = [
    "SURFACE_MODIFY_SPHERE_METADATA",
    "SurfaceModifySphereOutputs",
    "SurfaceModifySphereParamsDict",
    "SurfaceModifySphereParamsDictTagged",
    "surface_modify_sphere",
    "surface_modify_sphere_execute",
    "surface_modify_sphere_params",
]
