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

import typing
import pathlib
from styxdefs import *
import dataclasses

BETSURF_METADATA = Metadata(
    id="7a094f934968097bde54d5a6fbea512011c9f723.boutiques",
    name="betsurf",
    package="fsl",
    container_image_tag="brainlife/fsl:6.0.4-patched2",
)


class BetsurfOutputs(typing.NamedTuple):
    """
    Output object returned when calling `betsurf(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_mask: OutputPathType
    """Generated binary mask"""
    output_outline: OutputPathType
    """Generated surface outline"""
    output_skull: OutputPathType
    """Generated skull mask"""


def betsurf(
    t1_image: InputPathType,
    bet_mesh: InputPathType,
    t1_to_standard_mat: InputPathType,
    output_prefix: str,
    t2_image: InputPathType | None = None,
    help_flag: bool = False,
    verbose_flag: bool = False,
    t1only_flag: bool = False,
    outline_flag: bool = False,
    mask_flag: bool = False,
    skull_mask_flag: bool = False,
    increased_precision: int | None = None,
    runner: Runner | None = None,
) -> BetsurfOutputs:
    """
    BET Surface Finder to extract brain surfaces using T1 and T2 images.
    
    Author: FMRIB Analysis Group, University of Oxford
    
    URL: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki
    
    Args:
        t1_image: T1-weighted MRI image.
        bet_mesh: BET Mesh File (.vtk).
        t1_to_standard_mat: Transformation matrix file from T1 to standard\
            space.
        output_prefix: Output prefix for generated files.
        t2_image: T2-weighted MRI image (optional if using --t1only flag).
        help_flag: Displays help message and exits.
        verbose_flag: Switch on diagnostic messages.
        t1only_flag: Extraction with T1 only.
        outline_flag: Generates all surface outlines.
        mask_flag: Generates binary masks from the meshes.
        skull_mask_flag: Generates skull binary mask.
        increased_precision: Retessellates the meshes the indicated number of\
            times (int).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BetsurfOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(BETSURF_METADATA)
    cargs = []
    cargs.append("betsurf")
    cargs.append(execution.input_file(t1_image))
    if t2_image is not None:
        cargs.append(execution.input_file(t2_image))
    cargs.append(execution.input_file(bet_mesh))
    cargs.append(execution.input_file(t1_to_standard_mat))
    cargs.append(output_prefix)
    if help_flag:
        cargs.append("-h")
    if verbose_flag:
        cargs.append("-v")
    if t1only_flag:
        cargs.append("-1")
    if outline_flag:
        cargs.append("-o")
    if mask_flag:
        cargs.append("-m")
    if skull_mask_flag:
        cargs.append("-s")
    if increased_precision is not None:
        cargs.extend([
            "-p",
            str(increased_precision)
        ])
    ret = BetsurfOutputs(
        root=execution.output_file("."),
        output_mask=execution.output_file(output_prefix + "_mask.nii.gz"),
        output_outline=execution.output_file(output_prefix + "_outline.nii.gz"),
        output_skull=execution.output_file(output_prefix + "_skull.nii.gz"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "BETSURF_METADATA",
    "BetsurfOutputs",
    "betsurf",
]
