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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_AUTOMASK_METADATA = Metadata(
    id="4c4dea39415d0dfa3511b858d1bcbcf03ec341e6.boutiques",
    name="3dAutomask",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dAutomaskOutputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_automask(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    brain_file: OutputPathType
    """Output file from 3dautomask."""
    out_file: OutputPathType
    """Output image file name."""
    brain_file_: OutputPathType
    """Brain file (skull stripped)."""
    out_file_: OutputPathType
    """Mask file."""


def v_3d_automask(
    in_file: InputPathType,
    clfrac: float | None = None,
    dilate: int | None = None,
    erode: int | None = None,
    outputtype: typing.Literal["NIFTI", "AFNI", "NIFTI_GZ"] | None = None,
    runner: Runner | None = None,
) -> V3dAutomaskOutputs:
    """
    Create a brain-only mask of the image using AFNI 3dAutomask command.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dAutomask.html
    
    Args:
        in_file: Input file to 3dautomask.
        clfrac: Sets the clip level fraction (must be 0.1-0.9). a small value\
            will tend to make the mask larger [default = 0.5].
        dilate: Dilate the mask outwards.
        erode: Erode the mask inwards.
        outputtype: 'nifti' or 'afni' or 'nifti_gz'. Afni output filetype.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dAutomaskOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_AUTOMASK_METADATA)
    cargs = []
    cargs.append("3dAutomask")
    cargs.append(execution.input_file(in_file))
    cargs.append("[BRAIN_FILE]")
    if clfrac is not None:
        cargs.extend([
            "-clfrac",
            str(clfrac)
        ])
    if dilate is not None:
        cargs.extend([
            "-dilate",
            str(dilate)
        ])
    if erode is not None:
        cargs.extend([
            "-erode",
            str(erode)
        ])
    cargs.append("[OUT_FILE]")
    if outputtype is not None:
        cargs.append(outputtype)
    ret = V3dAutomaskOutputs(
        root=execution.output_file("."),
        brain_file=execution.output_file(pathlib.Path(in_file).name + "_masked"),
        out_file=execution.output_file(pathlib.Path(in_file).name + "_mask"),
        brain_file_=execution.output_file("brain_file"),
        out_file_=execution.output_file("out_file"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dAutomaskOutputs",
    "V_3D_AUTOMASK_METADATA",
    "v_3d_automask",
]
