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

import typing
import pathlib
from styxdefs import *

SURFACE_BASED_SMOOTHING_METADATA = Metadata(
    id="b2f8fe5e700adfbe15932f192ed3a9cf1462c8c5.boutiques",
    name="SurfaceBasedSmoothing",
    package="ants",
    container_image_tag="antsx/ants:v2.5.3",
)


_SurfaceBasedSmoothingParamsDictNoTag = typing.TypedDict('_SurfaceBasedSmoothingParamsDictNoTag', {
    "image_to_smooth": InputPathType,
    "sigma": float,
    "surface_image": InputPathType,
    "outname": str,
    "num_repeats": typing.NotRequired[int | None],
})
SurfaceBasedSmoothingParamsDictTagged = typing.TypedDict('SurfaceBasedSmoothingParamsDictTagged', {
    "@type": typing.Literal["ants/SurfaceBasedSmoothing"],
    "image_to_smooth": InputPathType,
    "sigma": float,
    "surface_image": InputPathType,
    "outname": str,
    "num_repeats": typing.NotRequired[int | None],
})
SurfaceBasedSmoothingParamsDict = _SurfaceBasedSmoothingParamsDictNoTag | SurfaceBasedSmoothingParamsDictTagged


class SurfaceBasedSmoothingOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SurfaceBasedSmoothingParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    smoothed_output: OutputPathType
    """The output smoothed image."""


def surface_based_smoothing_params(
    image_to_smooth: InputPathType,
    sigma: float,
    surface_image: InputPathType,
    outname: str,
    num_repeats: int | None = None,
) -> SurfaceBasedSmoothingParamsDictTagged:
    """
    Build parameters.
    
    Args:
        image_to_smooth: The image that needs to be smoothed.
        sigma: Geodesic neighborhood radius.
        surface_image: Assumes a label == 1 that defines the surface.
        outname: The name of the output file.
        num_repeats: Number of times the geodesic neighborhood is applied\
            repeatedly.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "ants/SurfaceBasedSmoothing",
        "image_to_smooth": image_to_smooth,
        "sigma": sigma,
        "surface_image": surface_image,
        "outname": outname,
    }
    if num_repeats is not None:
        params["num_repeats"] = num_repeats
    return params


def surface_based_smoothing_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceBasedSmoothingParamsDict` 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("image_to_smooth", None) is None:
        raise StyxValidationError("`image_to_smooth` must not be None")
    if not isinstance(params["image_to_smooth"], (pathlib.Path, str)):
        raise StyxValidationError(f'`image_to_smooth` has the wrong type: Received `{type(params.get("image_to_smooth", None))}` expected `InputPathType`')
    if params.get("sigma", None) is None:
        raise StyxValidationError("`sigma` must not be None")
    if not isinstance(params["sigma"], (float, int)):
        raise StyxValidationError(f'`sigma` has the wrong type: Received `{type(params.get("sigma", None))}` expected `float`')
    if params.get("surface_image", None) is None:
        raise StyxValidationError("`surface_image` must not be None")
    if not isinstance(params["surface_image"], (pathlib.Path, str)):
        raise StyxValidationError(f'`surface_image` has the wrong type: Received `{type(params.get("surface_image", None))}` expected `InputPathType`')
    if params.get("outname", None) is None:
        raise StyxValidationError("`outname` must not be None")
    if not isinstance(params["outname"], str):
        raise StyxValidationError(f'`outname` has the wrong type: Received `{type(params.get("outname", None))}` expected `str`')
    if params.get("num_repeats", None) is not None:
        if not isinstance(params["num_repeats"], int):
            raise StyxValidationError(f'`num_repeats` has the wrong type: Received `{type(params.get("num_repeats", None))}` expected `int | None`')


def surface_based_smoothing_cargs(
    params: SurfaceBasedSmoothingParamsDict,
    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.append("SurfaceBasedSmoothing")
    cargs.append(execution.input_file(params.get("image_to_smooth", None)))
    cargs.append(str(params.get("sigma", None)))
    cargs.append(execution.input_file(params.get("surface_image", None)))
    cargs.append(params.get("outname", None))
    if params.get("num_repeats", None) is not None:
        cargs.append(str(params.get("num_repeats", None)))
    return cargs


def surface_based_smoothing_outputs(
    params: SurfaceBasedSmoothingParamsDict,
    execution: Execution,
) -> SurfaceBasedSmoothingOutputs:
    """
    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 = SurfaceBasedSmoothingOutputs(
        root=execution.output_file("."),
        smoothed_output=execution.output_file(params.get("outname", None)),
    )
    return ret


def surface_based_smoothing_execute(
    params: SurfaceBasedSmoothingParamsDict,
    runner: Runner | None = None,
) -> SurfaceBasedSmoothingOutputs:
    """
    SurfaceBasedSmoothing
    
    Surface-based smoothing applied to ImageToSmooth using a geodesic
    neighbourhood defined by sigma and the surface image.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceBasedSmoothingOutputs`).
    """
    surface_based_smoothing_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_BASED_SMOOTHING_METADATA)
    params = execution.params(params)
    cargs = surface_based_smoothing_cargs(params, execution)
    ret = surface_based_smoothing_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_based_smoothing(
    image_to_smooth: InputPathType,
    sigma: float,
    surface_image: InputPathType,
    outname: str,
    num_repeats: int | None = None,
    runner: Runner | None = None,
) -> SurfaceBasedSmoothingOutputs:
    """
    SurfaceBasedSmoothing
    
    Surface-based smoothing applied to ImageToSmooth using a geodesic
    neighbourhood defined by sigma and the surface image.
    
    Author: ANTs Developers
    
    URL: https://github.com/ANTsX/ANTs
    
    Args:
        image_to_smooth: The image that needs to be smoothed.
        sigma: Geodesic neighborhood radius.
        surface_image: Assumes a label == 1 that defines the surface.
        outname: The name of the output file.
        num_repeats: Number of times the geodesic neighborhood is applied\
            repeatedly.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceBasedSmoothingOutputs`).
    """
    params = surface_based_smoothing_params(
        image_to_smooth=image_to_smooth,
        sigma=sigma,
        surface_image=surface_image,
        outname=outname,
        num_repeats=num_repeats,
    )
    return surface_based_smoothing_execute(params, runner)


__all__ = [
    "SURFACE_BASED_SMOOTHING_METADATA",
    "SurfaceBasedSmoothingOutputs",
    "SurfaceBasedSmoothingParamsDict",
    "SurfaceBasedSmoothingParamsDictTagged",
    "surface_based_smoothing",
    "surface_based_smoothing_execute",
    "surface_based_smoothing_params",
]
