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

import typing
import pathlib
from styxdefs import *
import dataclasses

DEFECT_SEG_METADATA = Metadata(
    id="0e4a4cf0254a2348ea18fc134e746047a23ee4d4.boutiques",
    name="defect-seg",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class DefectSegOutputs(typing.NamedTuple):
    """
    Output object returned when calling `defect_seg(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    surface_defects: OutputPathType
    """Surface defects volume."""
    defects_summary: OutputPathType
    """Summary of defects indicating numerical ID and number of vertices."""
    defect_labels_fix: OutputPathType
    """Fixed defect labels on the surface."""
    defect_labels_fix_bin: OutputPathType
    """Binary labels for fixed defects."""
    defects_nofix_annot: OutputPathType
    """Annotation file for defects without fixes."""
    defects_fix_annot: OutputPathType
    """Annotation file for defects with fixes."""
    defects_stats: OutputPathType
    """Statistics summary of defects indicating area and average thickness."""


def defect_seg(
    subject: str,
    lh_only: bool = False,
    rh_only: bool = False,
    runner: Runner | None = None,
) -> DefectSegOutputs:
    """
    This program creates some files that allows the user to visualize and evaluate
    the surface defects that were automatically detected and fixed by the topology
    correction program.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        subject: Subject identifier.
        lh_only: Only process the left hemisphere.
        rh_only: Only process the right hemisphere.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `DefectSegOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(DEFECT_SEG_METADATA)
    cargs = []
    cargs.append("defect-seg")
    cargs.extend([
        "--s",
        subject
    ])
    if lh_only:
        cargs.append("--lh-only")
    if rh_only:
        cargs.append("--rh-only")
    ret = DefectSegOutputs(
        root=execution.output_file("."),
        surface_defects=execution.output_file("mri/surface.defects.mgz"),
        defects_summary=execution.output_file("scripts/?h.defects.summary"),
        defect_labels_fix=execution.output_file("surf/?h.defect_labels.fix.mgz"),
        defect_labels_fix_bin=execution.output_file("surf/?h.defect_labels.fix.bin.mgz"),
        defects_nofix_annot=execution.output_file("label/?h.defects.nofix.annot"),
        defects_fix_annot=execution.output_file("label/?h.defects.fix.annot"),
        defects_stats=execution.output_file("stats/?h.defects.stats"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DEFECT_SEG_METADATA",
    "DefectSegOutputs",
    "defect_seg",
]
