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

import typing
import pathlib
from styxdefs import *

VOLUME_FILL_HOLES_METADATA = Metadata(
    id="447c0fe666083fe1acbc67cf224c9e527b125009.workbench",
    name="volume-fill-holes",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_VolumeFillHolesParamsDictNoTag = typing.TypedDict('_VolumeFillHolesParamsDictNoTag', {
    "volume-in": InputPathType,
    "volume-out": str,
})
VolumeFillHolesParamsDictTagged = typing.TypedDict('VolumeFillHolesParamsDictTagged', {
    "@type": typing.Literal["workbench/volume-fill-holes"],
    "volume-in": InputPathType,
    "volume-out": str,
})
VolumeFillHolesParamsDict = _VolumeFillHolesParamsDictNoTag | VolumeFillHolesParamsDictTagged


class VolumeFillHolesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `VolumeFillHolesParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    volume_out: OutputPathType
    """the output ROI volume"""


def volume_fill_holes_params(
    volume_in: InputPathType,
    volume_out: str,
) -> VolumeFillHolesParamsDictTagged:
    """
    Build parameters.
    
    Args:
        volume_in: the input ROI volume.
        volume_out: the output ROI volume.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/volume-fill-holes",
        "volume-in": volume_in,
        "volume-out": volume_out,
    }
    return params


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


def volume_fill_holes_cargs(
    params: VolumeFillHolesParamsDict,
    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",
        "-volume-fill-holes"
    ])
    cargs.append(execution.input_file(params.get("volume-in", None)))
    cargs.append(params.get("volume-out", None))
    return cargs


def volume_fill_holes_outputs(
    params: VolumeFillHolesParamsDict,
    execution: Execution,
) -> VolumeFillHolesOutputs:
    """
    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 = VolumeFillHolesOutputs(
        root=execution.output_file("."),
        volume_out=execution.output_file(params.get("volume-out", None)),
    )
    return ret


def volume_fill_holes_execute(
    params: VolumeFillHolesParamsDict,
    runner: Runner | None = None,
) -> VolumeFillHolesOutputs:
    """
    FILL HOLES IN AN ROI VOLUME.
    
    Finds all face-connected parts that are not included in the ROI, and fills
    all but the largest one with ones.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeFillHolesOutputs`).
    """
    volume_fill_holes_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(VOLUME_FILL_HOLES_METADATA)
    params = execution.params(params)
    cargs = volume_fill_holes_cargs(params, execution)
    ret = volume_fill_holes_outputs(params, execution)
    execution.run(cargs)
    return ret


def volume_fill_holes(
    volume_in: InputPathType,
    volume_out: str,
    runner: Runner | None = None,
) -> VolumeFillHolesOutputs:
    """
    FILL HOLES IN AN ROI VOLUME.
    
    Finds all face-connected parts that are not included in the ROI, and fills
    all but the largest one with ones.
    
    Args:
        volume_in: the input ROI volume.
        volume_out: the output ROI volume.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `VolumeFillHolesOutputs`).
    """
    params = volume_fill_holes_params(
        volume_in=volume_in,
        volume_out=volume_out,
    )
    return volume_fill_holes_execute(params, runner)


__all__ = [
    "VOLUME_FILL_HOLES_METADATA",
    "VolumeFillHolesOutputs",
    "VolumeFillHolesParamsDict",
    "VolumeFillHolesParamsDictTagged",
    "volume_fill_holes",
    "volume_fill_holes_execute",
    "volume_fill_holes_params",
]
