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

import typing
import pathlib
from styxdefs import *

SURFACE_INFLATION_METADATA = Metadata(
    id="9461f44d7d7d0b826502df0acb5b89588faca185.workbench",
    name="surface-inflation",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceInflationParamsDictNoTag = typing.TypedDict('_SurfaceInflationParamsDictNoTag', {
    "anatomical-surface-in": InputPathType,
    "surface-in": InputPathType,
    "number-of-smoothing-cycles": int,
    "smoothing-strength": float,
    "smoothing-iterations": int,
    "inflation-factor": float,
    "surface-out": str,
})
SurfaceInflationParamsDictTagged = typing.TypedDict('SurfaceInflationParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-inflation"],
    "anatomical-surface-in": InputPathType,
    "surface-in": InputPathType,
    "number-of-smoothing-cycles": int,
    "smoothing-strength": float,
    "smoothing-iterations": int,
    "inflation-factor": float,
    "surface-out": str,
})
SurfaceInflationParamsDict = _SurfaceInflationParamsDictNoTag | SurfaceInflationParamsDictTagged


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


def surface_inflation_params(
    anatomical_surface_in: InputPathType,
    surface_in: InputPathType,
    number_of_smoothing_cycles: int,
    smoothing_strength: float,
    smoothing_iterations: int,
    inflation_factor: float,
    surface_out: str,
) -> SurfaceInflationParamsDictTagged:
    """
    Build parameters.
    
    Args:
        anatomical_surface_in: the anatomical surface.
        surface_in: the surface file to inflate.
        number_of_smoothing_cycles: number of smoothing cycles.
        smoothing_strength: smoothing strength (ranges [0.0 - 1.0]).
        smoothing_iterations: smoothing iterations.
        inflation_factor: inflation factor.
        surface_out: output surface file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-inflation",
        "anatomical-surface-in": anatomical_surface_in,
        "surface-in": surface_in,
        "number-of-smoothing-cycles": number_of_smoothing_cycles,
        "smoothing-strength": smoothing_strength,
        "smoothing-iterations": smoothing_iterations,
        "inflation-factor": inflation_factor,
        "surface-out": surface_out,
    }
    return params


def surface_inflation_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceInflationParamsDict` 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("surface-in", None) is None:
        raise StyxValidationError("`surface-in` must not be None")
    if not isinstance(params["surface-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`surface-in` has the wrong type: Received `{type(params.get("surface-in", None))}` expected `InputPathType`')
    if params.get("number-of-smoothing-cycles", None) is None:
        raise StyxValidationError("`number-of-smoothing-cycles` must not be None")
    if not isinstance(params["number-of-smoothing-cycles"], int):
        raise StyxValidationError(f'`number-of-smoothing-cycles` has the wrong type: Received `{type(params.get("number-of-smoothing-cycles", None))}` expected `int`')
    if params.get("smoothing-strength", None) is None:
        raise StyxValidationError("`smoothing-strength` must not be None")
    if not isinstance(params["smoothing-strength"], (float, int)):
        raise StyxValidationError(f'`smoothing-strength` has the wrong type: Received `{type(params.get("smoothing-strength", None))}` expected `float`')
    if params.get("smoothing-iterations", None) is None:
        raise StyxValidationError("`smoothing-iterations` must not be None")
    if not isinstance(params["smoothing-iterations"], int):
        raise StyxValidationError(f'`smoothing-iterations` has the wrong type: Received `{type(params.get("smoothing-iterations", None))}` expected `int`')
    if params.get("inflation-factor", None) is None:
        raise StyxValidationError("`inflation-factor` must not be None")
    if not isinstance(params["inflation-factor"], (float, int)):
        raise StyxValidationError(f'`inflation-factor` has the wrong type: Received `{type(params.get("inflation-factor", None))}` expected `float`')
    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_inflation_cargs(
    params: SurfaceInflationParamsDict,
    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-inflation"
    ])
    cargs.append(execution.input_file(params.get("anatomical-surface-in", None)))
    cargs.append(execution.input_file(params.get("surface-in", None)))
    cargs.append(str(params.get("number-of-smoothing-cycles", None)))
    cargs.append(str(params.get("smoothing-strength", None)))
    cargs.append(str(params.get("smoothing-iterations", None)))
    cargs.append(str(params.get("inflation-factor", None)))
    cargs.append(params.get("surface-out", None))
    return cargs


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


def surface_inflation_execute(
    params: SurfaceInflationParamsDict,
    runner: Runner | None = None,
) -> SurfaceInflationOutputs:
    """
    SURFACE INFLATION.
    
    Inflate a surface by performing cycles that consist of smoothing followed by
    inflation (to correct shrinkage caused by smoothing).
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceInflationOutputs`).
    """
    surface_inflation_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_INFLATION_METADATA)
    params = execution.params(params)
    cargs = surface_inflation_cargs(params, execution)
    ret = surface_inflation_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_inflation(
    anatomical_surface_in: InputPathType,
    surface_in: InputPathType,
    number_of_smoothing_cycles: int,
    smoothing_strength: float,
    smoothing_iterations: int,
    inflation_factor: float,
    surface_out: str,
    runner: Runner | None = None,
) -> SurfaceInflationOutputs:
    """
    SURFACE INFLATION.
    
    Inflate a surface by performing cycles that consist of smoothing followed by
    inflation (to correct shrinkage caused by smoothing).
    
    Args:
        anatomical_surface_in: the anatomical surface.
        surface_in: the surface file to inflate.
        number_of_smoothing_cycles: number of smoothing cycles.
        smoothing_strength: smoothing strength (ranges [0.0 - 1.0]).
        smoothing_iterations: smoothing iterations.
        inflation_factor: inflation factor.
        surface_out: output surface file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceInflationOutputs`).
    """
    params = surface_inflation_params(
        anatomical_surface_in=anatomical_surface_in,
        surface_in=surface_in,
        number_of_smoothing_cycles=number_of_smoothing_cycles,
        smoothing_strength=smoothing_strength,
        smoothing_iterations=smoothing_iterations,
        inflation_factor=inflation_factor,
        surface_out=surface_out,
    )
    return surface_inflation_execute(params, runner)


__all__ = [
    "SURFACE_INFLATION_METADATA",
    "SurfaceInflationOutputs",
    "SurfaceInflationParamsDict",
    "SurfaceInflationParamsDictTagged",
    "surface_inflation",
    "surface_inflation_execute",
    "surface_inflation_params",
]
