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

import typing
import pathlib
from styxdefs import *

SURFACE_CREATE_SPHERE_METADATA = Metadata(
    id="bed788743061812c1852a66ee0671bb89ebb21bd.workbench",
    name="surface-create-sphere",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceCreateSphereParamsDictNoTag = typing.TypedDict('_SurfaceCreateSphereParamsDictNoTag', {
    "num-vertices": int,
    "sphere-out": str,
})
SurfaceCreateSphereParamsDictTagged = typing.TypedDict('SurfaceCreateSphereParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-create-sphere"],
    "num-vertices": int,
    "sphere-out": str,
})
SurfaceCreateSphereParamsDict = _SurfaceCreateSphereParamsDictNoTag | SurfaceCreateSphereParamsDictTagged


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


def surface_create_sphere_params(
    num_vertices: int,
    sphere_out: str,
) -> SurfaceCreateSphereParamsDictTagged:
    """
    Build parameters.
    
    Args:
        num_vertices: desired number of vertices.
        sphere_out: the output sphere.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-create-sphere",
        "num-vertices": num_vertices,
        "sphere-out": sphere_out,
    }
    return params


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


def surface_create_sphere_cargs(
    params: SurfaceCreateSphereParamsDict,
    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-create-sphere"
    ])
    cargs.append(str(params.get("num-vertices", None)))
    cargs.append(params.get("sphere-out", None))
    return cargs


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


def surface_create_sphere_execute(
    params: SurfaceCreateSphereParamsDict,
    runner: Runner | None = None,
) -> SurfaceCreateSphereOutputs:
    """
    GENERATE A SPHERE WITH CONSISTENT VERTEX AREAS.
    
    Generates a sphere by regularly dividing the triangles of an icosahedron, to
    come as close to the desired number of vertices as possible, and modifying
    it to have very similar vertex areas for all vertices. To generate a pair of
    vertex-matched left and right spheres, use this command, then
    -surface-flip-lr to generate the other sphere, then -set-structure on each.
    For example:
    
    $ wb_command -surface-create-sphere 6000 Sphere.6k.R.surf.gii
    $ wb_command -surface-flip-lr Sphere.6k.R.surf.gii Sphere.6k.L.surf.gii
    $ wb_command -set-structure Sphere.6k.R.surf.gii CORTEX_RIGHT
    $ wb_command -set-structure Sphere.6k.L.surf.gii CORTEX_LEFT.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCreateSphereOutputs`).
    """
    surface_create_sphere_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_CREATE_SPHERE_METADATA)
    params = execution.params(params)
    cargs = surface_create_sphere_cargs(params, execution)
    ret = surface_create_sphere_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_create_sphere(
    num_vertices: int,
    sphere_out: str,
    runner: Runner | None = None,
) -> SurfaceCreateSphereOutputs:
    """
    GENERATE A SPHERE WITH CONSISTENT VERTEX AREAS.
    
    Generates a sphere by regularly dividing the triangles of an icosahedron, to
    come as close to the desired number of vertices as possible, and modifying
    it to have very similar vertex areas for all vertices. To generate a pair of
    vertex-matched left and right spheres, use this command, then
    -surface-flip-lr to generate the other sphere, then -set-structure on each.
    For example:
    
    $ wb_command -surface-create-sphere 6000 Sphere.6k.R.surf.gii
    $ wb_command -surface-flip-lr Sphere.6k.R.surf.gii Sphere.6k.L.surf.gii
    $ wb_command -set-structure Sphere.6k.R.surf.gii CORTEX_RIGHT
    $ wb_command -set-structure Sphere.6k.L.surf.gii CORTEX_LEFT.
    
    Args:
        num_vertices: desired number of vertices.
        sphere_out: the output sphere.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceCreateSphereOutputs`).
    """
    params = surface_create_sphere_params(
        num_vertices=num_vertices,
        sphere_out=sphere_out,
    )
    return surface_create_sphere_execute(params, runner)


__all__ = [
    "SURFACE_CREATE_SPHERE_METADATA",
    "SurfaceCreateSphereOutputs",
    "SurfaceCreateSphereParamsDict",
    "SurfaceCreateSphereParamsDictTagged",
    "surface_create_sphere",
    "surface_create_sphere_execute",
    "surface_create_sphere_params",
]
