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

import typing
import pathlib
from styxdefs import *

METRIC_FILL_HOLES_METADATA = Metadata(
    id="ac7f75738ed2f6a51844159ab8a7e0af250545a8.boutiques",
    name="metric-fill-holes",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


MetricFillHolesParameters = typing.TypedDict('MetricFillHolesParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/metric-fill-holes"]],
    "surface": InputPathType,
    "metric_in": InputPathType,
    "metric_out": str,
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})
MetricFillHolesParametersTagged = typing.TypedDict('MetricFillHolesParametersTagged', {
    "@type": typing.Literal["workbench/metric-fill-holes"],
    "surface": InputPathType,
    "metric_in": InputPathType,
    "metric_out": str,
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
})


class MetricFillHolesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `MetricFillHolesParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    metric_out: OutputPathType
    """the output ROI metric"""


def metric_fill_holes_params(
    surface: InputPathType,
    metric_in: InputPathType,
    metric_out: str,
    opt_corrected_areas_area_metric: InputPathType | None = None,
) -> MetricFillHolesParametersTagged:
    """
    Build parameters.
    
    Args:
        surface: the surface to use for neighbor information.
        metric_in: the input ROI metric.
        metric_out: the output ROI metric.
        opt_corrected_areas_area_metric: vertex areas to use instead of\
            computing them from the surface: the corrected vertex areas, as a\
            metric.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/metric-fill-holes",
        "surface": surface,
        "metric_in": metric_in,
        "metric_out": metric_out,
    }
    if opt_corrected_areas_area_metric is not None:
        params["opt_corrected_areas_area_metric"] = opt_corrected_areas_area_metric
    return params


def metric_fill_holes_cargs(
    params: MetricFillHolesParameters,
    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("wb_command")
    cargs.append("-metric-fill-holes")
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(execution.input_file(params.get("metric_in", None)))
    cargs.append(params.get("metric_out", None))
    if params.get("opt_corrected_areas_area_metric", None) is not None:
        cargs.extend([
            "-corrected-areas",
            execution.input_file(params.get("opt_corrected_areas_area_metric", None))
        ])
    return cargs


def metric_fill_holes_outputs(
    params: MetricFillHolesParameters,
    execution: Execution,
) -> MetricFillHolesOutputs:
    """
    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 = MetricFillHolesOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric_out", None)),
    )
    return ret


def metric_fill_holes_execute(
    params: MetricFillHolesParameters,
    runner: Runner | None = None,
) -> MetricFillHolesOutputs:
    """
    metric-fill-holes
    
    Fill holes in an roi metric.
    
    Finds all connected areas that are not included in the ROI, and writes ones
    into all but the largest one, in terms of surface area.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricFillHolesOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(METRIC_FILL_HOLES_METADATA)
    params = execution.params(params)
    cargs = metric_fill_holes_cargs(params, execution)
    ret = metric_fill_holes_outputs(params, execution)
    execution.run(cargs)
    return ret


def metric_fill_holes(
    surface: InputPathType,
    metric_in: InputPathType,
    metric_out: str,
    opt_corrected_areas_area_metric: InputPathType | None = None,
    runner: Runner | None = None,
) -> MetricFillHolesOutputs:
    """
    metric-fill-holes
    
    Fill holes in an roi metric.
    
    Finds all connected areas that are not included in the ROI, and writes ones
    into all but the largest one, in terms of surface area.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        surface: the surface to use for neighbor information.
        metric_in: the input ROI metric.
        metric_out: the output ROI metric.
        opt_corrected_areas_area_metric: vertex areas to use instead of\
            computing them from the surface: the corrected vertex areas, as a\
            metric.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MetricFillHolesOutputs`).
    """
    params = metric_fill_holes_params(
        surface=surface,
        metric_in=metric_in,
        metric_out=metric_out,
        opt_corrected_areas_area_metric=opt_corrected_areas_area_metric,
    )
    return metric_fill_holes_execute(params, runner)


__all__ = [
    "METRIC_FILL_HOLES_METADATA",
    "MetricFillHolesOutputs",
    "metric_fill_holes",
    "metric_fill_holes_execute",
    "metric_fill_holes_params",
]
