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

import typing
import pathlib
from styxdefs import *
import dataclasses

DEFECT2SEG_METADATA = Metadata(
    id="8cc085b9f5ac3b7cb657915baccb8e34277b70f2.boutiques",
    name="defect2seg",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class Defect2segOutputs(typing.NamedTuple):
    """
    Output object returned when calling `defect2seg(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output_segmentation: OutputPathType
    """Resulting defect segmentation volume"""


def defect2seg(
    output_seg: InputPathType,
    template: InputPathType,
    left_hemisphere: list[str] | None = None,
    right_hemisphere: list[str] | None = None,
    subject: str | None = None,
    lh_only: bool = False,
    rh_only: bool = False,
    cortex: bool = False,
    no_cortex: bool = False,
    runner: Runner | None = None,
) -> Defect2segOutputs:
    """
    Converts surface defect labels into a segmentation volume and pointsets.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        output_seg: Output segmentation volume.
        template: Template for segmentation.
        left_hemisphere: Left hemisphere inputs: surface, defect labels,\
            pointset, and offset.
        right_hemisphere: Right hemisphere inputs: surface, defect labels,\
            pointset, and offset.
        subject: Subject identifier, sets default values for other parameters.
        lh_only: Consider only left hemisphere defects.
        rh_only: Consider only right hemisphere defects.
        cortex: Constrain defects to within cortex.
        no_cortex: Allow defects outside of cortex.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `Defect2segOutputs`).
    """
    if left_hemisphere is not None and not (len(left_hemisphere) <= 4): 
        raise ValueError(f"Length of 'left_hemisphere' must be less than 4 but was {len(left_hemisphere)}")
    if right_hemisphere is not None and not (len(right_hemisphere) <= 4): 
        raise ValueError(f"Length of 'right_hemisphere' must be less than 4 but was {len(right_hemisphere)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(DEFECT2SEG_METADATA)
    cargs = []
    cargs.append("defect2seg")
    cargs.extend([
        "--o",
        execution.input_file(output_seg)
    ])
    cargs.extend([
        "--t",
        execution.input_file(template)
    ])
    if left_hemisphere is not None:
        cargs.extend([
            "--lh",
            *left_hemisphere
        ])
    if right_hemisphere is not None:
        cargs.extend([
            "--rh",
            *right_hemisphere
        ])
    if subject is not None:
        cargs.extend([
            "--s",
            subject
        ])
    if lh_only:
        cargs.append("--lh-only")
    if rh_only:
        cargs.append("--rh-only")
    if cortex:
        cargs.append("--cortex")
    if no_cortex:
        cargs.append("--no-cortex")
    ret = Defect2segOutputs(
        root=execution.output_file("."),
        output_segmentation=execution.output_file(pathlib.Path(output_seg).name),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "DEFECT2SEG_METADATA",
    "Defect2segOutputs",
    "defect2seg",
]
