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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRIS_EXVIVO_SURFACES_METADATA = Metadata(
    id="6158a382349b4ec3826fd3779a0f0dfa5790c075.boutiques",
    name="mris_exvivo_surfaces",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MrisExvivoSurfacesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mris_exvivo_surfaces(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    white_surface: OutputPathType
    """Generated white matter surface file"""
    gray_surface: OutputPathType
    """Generated gray matter surface file"""
    curvature_file: OutputPathType
    """Curvature file for cortical thickness"""
    layer_iv_surface: OutputPathType
    """Surface file approximating layer IV of the cortical sheet"""


def mris_exvivo_surfaces(
    subject_name: str,
    hemisphere: str,
    omit_self_intersection: bool = False,
    create_curvature_area: bool = False,
    average_curvature: float | None = 10,
    white_only: bool = False,
    formalin: int | None = None,
    runner: Runner | None = None,
) -> MrisExvivoSurfacesOutputs:
    """
    FreeSurfer tool to position tessellation of the cortical surface at the white
    and gray matter surfaces, and generate relevant surface files.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        subject_name: Name of the subject.
        hemisphere: Hemisphere (e.g., lh or rh).
        omit_self_intersection: Omit self-intersection check and only generate\
            gray/white surface.
        create_curvature_area: Create curvature and area files from white\
            matter surface.
        average_curvature: Average curvature values a specified number of\
            times.
        white_only: Only generate the white matter surface.
        formalin: Assume hemisphere is in formalin, with provided value\
            indicating presence (0,1).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MrisExvivoSurfacesOutputs`).
    """
    if formalin is not None and not (0 <= formalin <= 1): 
        raise ValueError(f"'formalin' must be between 0 <= x <= 1 but was {formalin}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRIS_EXVIVO_SURFACES_METADATA)
    cargs = []
    cargs.append("mris_exvivo_surfaces")
    cargs.append(subject_name)
    cargs.append(hemisphere)
    if omit_self_intersection:
        cargs.append("-q")
    if create_curvature_area:
        cargs.append("-c")
    if average_curvature is not None:
        cargs.extend([
            "-a",
            str(average_curvature)
        ])
    if white_only:
        cargs.append("-whiteonly")
    if formalin is not None:
        cargs.extend([
            "-formalin",
            str(formalin)
        ])
    ret = MrisExvivoSurfacesOutputs(
        root=execution.output_file("."),
        white_surface=execution.output_file("<subject_name>_<hemisphere>_white"),
        gray_surface=execution.output_file("<subject_name>_<hemisphere>_gray"),
        curvature_file=execution.output_file("<subject_name>_<hemisphere>_curvature"),
        layer_iv_surface=execution.output_file("<subject_name>_<hemisphere>_layerIV"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRIS_EXVIVO_SURFACES_METADATA",
    "MrisExvivoSurfacesOutputs",
    "mris_exvivo_surfaces",
]
