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

import typing
import pathlib
from styxdefs import *

SURFACE_GENERATE_INFLATED_METADATA = Metadata(
    id="355a98e0d7f2dd37d2a8db3706f4c44d3c0fd8e8.workbench",
    name="surface-generate-inflated",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceGenerateInflatedParamsDictNoTag = typing.TypedDict('_SurfaceGenerateInflatedParamsDictNoTag', {
    "anatomical-surface-in": InputPathType,
    "inflated-surface-out": str,
    "very-inflated-surface-out": str,
    "iterations-scale-value": typing.NotRequired[float | None],
})
SurfaceGenerateInflatedParamsDictTagged = typing.TypedDict('SurfaceGenerateInflatedParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-generate-inflated"],
    "anatomical-surface-in": InputPathType,
    "inflated-surface-out": str,
    "very-inflated-surface-out": str,
    "iterations-scale-value": typing.NotRequired[float | None],
})
SurfaceGenerateInflatedParamsDict = _SurfaceGenerateInflatedParamsDictNoTag | SurfaceGenerateInflatedParamsDictTagged


class SurfaceGenerateInflatedOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceGenerateInflatedParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    inflated_surface_out: OutputPathType
    """the output inflated surface"""
    very_inflated_surface_out: OutputPathType
    """the output very inflated surface"""


def surface_generate_inflated_params(
    anatomical_surface_in: InputPathType,
    inflated_surface_out: str,
    very_inflated_surface_out: str,
    iterations_scale_value: float | None = None,
) -> SurfaceGenerateInflatedParamsDictTagged:
    """
    Build parameters.
    
    Args:
        anatomical_surface_in: the anatomical surface.
        inflated_surface_out: the output inflated surface.
        very_inflated_surface_out: the output very inflated surface.
        iterations_scale_value: optional iterations scaling\
            \
            iterations-scale value.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-generate-inflated",
        "anatomical-surface-in": anatomical_surface_in,
        "inflated-surface-out": inflated_surface_out,
        "very-inflated-surface-out": very_inflated_surface_out,
    }
    if iterations_scale_value is not None:
        params["iterations-scale-value"] = iterations_scale_value
    return params


def surface_generate_inflated_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceGenerateInflatedParamsDict` 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("anatomical-surface-in", None) is None:
        raise StyxValidationError("`anatomical-surface-in` must not be None")
    if not isinstance(params["anatomical-surface-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`anatomical-surface-in` has the wrong type: Received `{type(params.get("anatomical-surface-in", None))}` expected `InputPathType`')
    if params.get("inflated-surface-out", None) is None:
        raise StyxValidationError("`inflated-surface-out` must not be None")
    if not isinstance(params["inflated-surface-out"], str):
        raise StyxValidationError(f'`inflated-surface-out` has the wrong type: Received `{type(params.get("inflated-surface-out", None))}` expected `str`')
    if params.get("very-inflated-surface-out", None) is None:
        raise StyxValidationError("`very-inflated-surface-out` must not be None")
    if not isinstance(params["very-inflated-surface-out"], str):
        raise StyxValidationError(f'`very-inflated-surface-out` has the wrong type: Received `{type(params.get("very-inflated-surface-out", None))}` expected `str`')
    if params.get("iterations-scale-value", None) is not None:
        if not isinstance(params["iterations-scale-value"], (float, int)):
            raise StyxValidationError(f'`iterations-scale-value` has the wrong type: Received `{type(params.get("iterations-scale-value", None))}` expected `float | None`')


def surface_generate_inflated_cargs(
    params: SurfaceGenerateInflatedParamsDict,
    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-generate-inflated"
    ])
    cargs.append(execution.input_file(params.get("anatomical-surface-in", None)))
    cargs.append(params.get("inflated-surface-out", None))
    cargs.append(params.get("very-inflated-surface-out", None))
    if params.get("iterations-scale-value", None) is not None:
        cargs.extend([
            "-iterations-scale",
            str(params.get("iterations-scale-value", None))
        ])
    return cargs


def surface_generate_inflated_outputs(
    params: SurfaceGenerateInflatedParamsDict,
    execution: Execution,
) -> SurfaceGenerateInflatedOutputs:
    """
    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 = SurfaceGenerateInflatedOutputs(
        root=execution.output_file("."),
        inflated_surface_out=execution.output_file(params.get("inflated-surface-out", None)),
        very_inflated_surface_out=execution.output_file(params.get("very-inflated-surface-out", None)),
    )
    return ret


def surface_generate_inflated_execute(
    params: SurfaceGenerateInflatedParamsDict,
    runner: Runner | None = None,
) -> SurfaceGenerateInflatedOutputs:
    """
    SURFACE GENERATE INFLATED.
    
    Generate inflated and very inflated surfaces. The output surfaces are
    'matched' (have same XYZ range) to the anatomical surface. In most cases, an
    iterations-scale of 1.0 (default) is sufficient. However, if the surface
    contains a large number of vertices (150,000), try an iterations-scale of
    2.5.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceGenerateInflatedOutputs`).
    """
    surface_generate_inflated_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_GENERATE_INFLATED_METADATA)
    params = execution.params(params)
    cargs = surface_generate_inflated_cargs(params, execution)
    ret = surface_generate_inflated_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_generate_inflated(
    anatomical_surface_in: InputPathType,
    inflated_surface_out: str,
    very_inflated_surface_out: str,
    iterations_scale_value: float | None = None,
    runner: Runner | None = None,
) -> SurfaceGenerateInflatedOutputs:
    """
    SURFACE GENERATE INFLATED.
    
    Generate inflated and very inflated surfaces. The output surfaces are
    'matched' (have same XYZ range) to the anatomical surface. In most cases, an
    iterations-scale of 1.0 (default) is sufficient. However, if the surface
    contains a large number of vertices (150,000), try an iterations-scale of
    2.5.
    
    Args:
        anatomical_surface_in: the anatomical surface.
        inflated_surface_out: the output inflated surface.
        very_inflated_surface_out: the output very inflated surface.
        iterations_scale_value: optional iterations scaling\
            \
            iterations-scale value.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceGenerateInflatedOutputs`).
    """
    params = surface_generate_inflated_params(
        anatomical_surface_in=anatomical_surface_in,
        inflated_surface_out=inflated_surface_out,
        very_inflated_surface_out=very_inflated_surface_out,
        iterations_scale_value=iterations_scale_value,
    )
    return surface_generate_inflated_execute(params, runner)


__all__ = [
    "SURFACE_GENERATE_INFLATED_METADATA",
    "SurfaceGenerateInflatedOutputs",
    "SurfaceGenerateInflatedParamsDict",
    "SurfaceGenerateInflatedParamsDictTagged",
    "surface_generate_inflated",
    "surface_generate_inflated_execute",
    "surface_generate_inflated_params",
]
