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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_STOPMASK_METADATA = Metadata(
    id="e7f2a3c2cfe3f7fafce248b01fa340177fa54cc2.boutiques",
    name="mri_stopmask",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriStopmaskOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_stopmask(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    generated_mask: OutputPathType
    """The generated stop mask output file"""


def mri_stopmask(
    output_mask: str,
    filled: list[InputPathType],
    aseg_presurf: InputPathType,
    lateral_ventricles: bool = False,
    wmsa: float | None = None,
    wm_voxels: InputPathType | None = None,
    brain_final_surfs: InputPathType | None = None,
    no_filled: bool = False,
    no_lv: bool = False,
    no_wmsa: bool = False,
    no_wm: bool = False,
    no_bfs: bool = False,
    runner: Runner | None = None,
) -> MriStopmaskOutputs:
    """
    This program creates a mask used to stop the search for the maximum gradient in
    mris_place_surface, preventing the surface from wandering into areas it should
    not.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        output_mask: Output stop mask in volume format.
        filled: Include voxels edited fill voxels that are set in the\
            filled.mgz.
        aseg_presurf: Used with --lv and/or --wmsa; Note: must be\
            aseg.presurf.mgz, not aseg.mgz.
        lateral_ventricles: Add lateral ventricles and choroid plexus to the\
            mask (needs --aseg).
        wmsa: Add WM hypointensities to the mask (needs --aseg); erode by given\
            distance away from any adjacent cortex.
        wm_voxels: Include voxels that =255 from wm.mgz.
        brain_final_surfs: Include voxels that =255 from brain.finalsurfs.mgz.
        no_filled: Turns off --filled option.
        no_lv: Turns off --lv option.
        no_wmsa: Turns off --wmsa option.
        no_wm: Turns off --wm option.
        no_bfs: Turns off --bfs option.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriStopmaskOutputs`).
    """
    if not (len(filled) <= 2): 
        raise ValueError(f"Length of 'filled' must be less than 2 but was {len(filled)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_STOPMASK_METADATA)
    cargs = []
    cargs.append("mri_stopmask")
    cargs.extend([
        "--o",
        output_mask
    ])
    cargs.extend([
        "--filled",
        *[execution.input_file(f) for f in filled]
    ])
    cargs.extend([
        "--aseg",
        execution.input_file(aseg_presurf)
    ])
    if lateral_ventricles:
        cargs.append("--lv")
    if wmsa is not None:
        cargs.extend([
            "--wmsa",
            str(wmsa)
        ])
    if wm_voxels is not None:
        cargs.extend([
            "--wm",
            execution.input_file(wm_voxels)
        ])
    if brain_final_surfs is not None:
        cargs.extend([
            "--bfs",
            execution.input_file(brain_final_surfs)
        ])
    if no_filled:
        cargs.append("--no-filled")
    if no_lv:
        cargs.append("--no-lv")
    if no_wmsa:
        cargs.append("--no-wmsa")
    if no_wm:
        cargs.append("--no-wm")
    if no_bfs:
        cargs.append("--no-bfs")
    ret = MriStopmaskOutputs(
        root=execution.output_file("."),
        generated_mask=execution.output_file(output_mask),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_STOPMASK_METADATA",
    "MriStopmaskOutputs",
    "mri_stopmask",
]
