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

import typing
import pathlib
from styxdefs import *
import dataclasses

SEG2FILLED_METADATA = Metadata(
    id="894fcea3b0a2a4a1b34ad187f3a8016973d50857.boutiques",
    name="seg2filled",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class Seg2filledOutputs(typing.NamedTuple):
    """
    Output object returned when calling `seg2filled(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    out_filled_mgz: OutputPathType
    """The output filled MGZ file."""


def seg2filled(
    seg_file: InputPathType,
    norm_file: InputPathType,
    output_file: str,
    ndil: int | None = None,
    cavity_flag: bool = False,
    surf_name: str | None = None,
    surf_dir: str | None = None,
    runner: Runner | None = None,
) -> Seg2filledOutputs:
    """
    Creates a filled.mgz from an aseg-style segmentation using SAMSEG segmentation.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        seg_file: Input aseg-style segmentation file (e.g., seg.mgz).
        norm_file: Normalization file (e.g., norm.mgz).
        output_file: Filled output file (e.g., filled.mgz).
        ndil: Number of iterations for dilation used to speed cavity detection.
        cavity_flag: Simulate a cavity to test the filling operation.
        surf_name: Name for the surface output (creates ?h.surfname).
        surf_dir: Directory to put the surface (default is same as filled).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Seg2filledOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(SEG2FILLED_METADATA)
    cargs = []
    cargs.append("seg2filled")
    cargs.extend([
        "-seg",
        "-" + execution.input_file(seg_file)
    ])
    cargs.extend([
        "-norm",
        "-" + execution.input_file(norm_file)
    ])
    cargs.extend([
        "-o",
        "-" + output_file
    ])
    if ndil is not None:
        cargs.extend([
            "--ndil",
            str(ndil)
        ])
    if cavity_flag:
        cargs.append("--cavity")
    if surf_name is not None:
        cargs.extend([
            "--surf",
            surf_name
        ])
    if surf_dir is not None:
        cargs.extend([
            "--surfdir",
            surf_dir
        ])
    ret = Seg2filledOutputs(
        root=execution.output_file("."),
        out_filled_mgz=execution.output_file(output_file),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "SEG2FILLED_METADATA",
    "Seg2filledOutputs",
    "seg2filled",
]
