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

import typing
import pathlib
from styxdefs import *
import dataclasses

V_3D_ANOVA3_METADATA = Metadata(
    id="9848d10813d27662b8bd1fcf297dabbe1fca2a7a.boutiques",
    name="3dANOVA3",
    package="afni",
    container_image_tag="afni/afni_make_build:AFNI_24.2.06",
)


class V3dAnova3Outputs(typing.NamedTuple):
    """
    Output object returned when calling `v_3d_anova3(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    outfile_fa: OutputPathType
    """Output file for the main ANOVA result."""
    outfile_fb: OutputPathType
    """Output file for the main B ANOVA result."""
    outfile_fc: OutputPathType
    """Output file for the main C ANOVA result."""
    outfile_fab: OutputPathType
    """Output file for the interaction between A and B."""
    outfile_fac: OutputPathType
    """Output file for the interaction between A and C."""
    outfile_fbc: OutputPathType
    """Output file for the interaction between B and C."""
    outfile_fabc: OutputPathType
    """Output file for the interaction between A, B, and C."""
    outfile_amean: OutputPathType
    """Output file for the A mean results."""
    outfile_bmean: OutputPathType
    """Output file for the B mean results."""


def v_3d_anova3(
    type_: int,
    alevels: int,
    blevels: int,
    clevels: int,
    dsets: list[str],
    voxel_num: int | None = None,
    diskspace: bool = False,
    mask: InputPathType | None = None,
    anova_options: list[str] | None = None,
    runner: Runner | None = None,
) -> V3dAnova3Outputs:
    """
    Performs three-factor ANOVA on 3D data sets.
    
    Author: AFNI Team
    
    URL: https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dANOVA3.html
    
    Args:
        type_: Type of ANOVA model to be used. k = 1: A,B,C fixed; AxBxC, k =\
            2: A,B,C random; AxBxC, k = 3: A fixed; B,C random; AxBxC, k = 4: A,B\
            fixed; C random; AxBxC, k = 5: A,B fixed; C random; AxB,BxC,C(A).
        alevels: Number of levels for factor A.
        blevels: Number of levels for factor B.
        clevels: Number of levels for factor C.
        dsets: Input data sets for specific levels of factors A, B, and C.
        voxel_num: Screen output for specified voxel number.
        diskspace: Print out disk space required for program execution.
        mask: Use sub-brick #0 of dataset to define which voxels to process.
        anova_options: Modified ANOVA computation options. See:\
            https://afni.nimh.nih.gov/sscc/gangc/ANOVA_Mod.html.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `V3dAnova3Outputs`).
    """
    if not (1 <= type_ <= 5): 
        raise ValueError(f"'type_' must be between 1 <= x <= 5 but was {type_}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(V_3D_ANOVA3_METADATA)
    cargs = []
    cargs.append("3dANOVA3")
    cargs.append("-type")
    cargs.extend([
        "-type",
        str(type_)
    ])
    cargs.append("-alevels")
    cargs.extend([
        "-alevels",
        str(alevels)
    ])
    cargs.append("-blevels")
    cargs.extend([
        "-blevels",
        str(blevels)
    ])
    cargs.append("-clevels")
    cargs.extend([
        "-clevels",
        str(clevels)
    ])
    cargs.extend([
        "-dset",
        *dsets
    ])
    if voxel_num is not None:
        cargs.extend([
            "-voxel",
            str(voxel_num)
        ])
    if diskspace:
        cargs.append("-diskspace")
    if mask is not None:
        cargs.extend([
            "-mask",
            execution.input_file(mask)
        ])
    cargs.append("[OUTFILES]")
    if anova_options is not None:
        cargs.extend([
            "-old_method -OK -assume_sph",
            *anova_options
        ])
    ret = V3dAnova3Outputs(
        root=execution.output_file("."),
        outfile_fa=execution.output_file("[OUTFILE_FA]"),
        outfile_fb=execution.output_file("[OUTFILE_FB]"),
        outfile_fc=execution.output_file("[OUTFILE_FC]"),
        outfile_fab=execution.output_file("[OUTFILE_FAB]"),
        outfile_fac=execution.output_file("[OUTFILE_FAC]"),
        outfile_fbc=execution.output_file("[OUTFILE_FBC]"),
        outfile_fabc=execution.output_file("[OUTFILE_FABC]"),
        outfile_amean=execution.output_file("[OUTFILE_AMEAN]"),
        outfile_bmean=execution.output_file("[OUTFILE_BMEAN]"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "V3dAnova3Outputs",
    "V_3D_ANOVA3_METADATA",
    "v_3d_anova3",
]
