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

import typing
import pathlib
from styxdefs import *
import dataclasses

MRI_MCSIM_METADATA = Metadata(
    id="c93d6e308a5345c3826d6a5f805dbcd44a658fe1.boutiques",
    name="mri_mcsim",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MriMcsimOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mri_mcsim(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    csd_output: OutputPathType
    """Output CSD files based on the base name"""
    done_output: OutputPathType | None
    """Done file created upon completion"""
    iteration_save: OutputPathType | None
    """Iteration save file"""
    log_output: OutputPathType | None
    """Log file generated during execution"""


def mri_mcsim(
    top_output_dir: str,
    base_name: str,
    surface: list[str],
    num_repetitions: float,
    fwhm_values: list[float] | None = None,
    fwhm_max: float | None = None,
    avg_vertex_area: bool = False,
    random_seed: float | None = None,
    label_file: InputPathType | None = None,
    mask_file: InputPathType | None = None,
    no_label: bool = False,
    no_save_mask: bool = False,
    surface_name: str | None = None,
    log_file: str | None = None,
    done_file: str | None = None,
    stop_file: str | None = None,
    save_file: str | None = None,
    save_iter: bool = False,
    subjects_dir: str | None = None,
    debug: bool = False,
    check_opts: bool = False,
    help_: bool = False,
    version: bool = False,
    runner: Runner | None = None,
) -> MriMcsimOutputs:
    """
    Monte Carlo simulation tool for surface-based multiple comparisons.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        top_output_dir: Top output directory.
        base_name: Base name for CSD files.
        surface: Subject name and hemisphere for the surface (e.g., subjectname\
            lh).
        num_repetitions: Number of repetitions for the simulation.
        fwhm_values: Full Width at Half Maximum values for smoothing.
        fwhm_max: Maximum FWHM for simulation (default 30).
        avg_vertex_area: Report cluster area based on average vertex area.
        random_seed: Random seed value (default is based on Time of Day).
        label_file: Label file for masking (default is ?h.cortex.label).
        mask_file: Mask file instead of label.
        no_label: Do not use a label to mask.
        no_save_mask: Do not save mask to output.
        surface_name: Surface name (default is white).
        log_file: Log file for the output.
        done_file: Done file to create when finished.
        stop_file: Stop file (default is ourdir/mri_mcsim.stop).
        save_file: Save file (default is ourdir/mri_mcsim.save).
        save_iter: Save output after each iteration.
        subjects_dir: Subjects directory.
        debug: Turn on debugging.
        check_opts: Check options do not run.
        help_: Display help message.
        version: Display version and exit.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MriMcsimOutputs`).
    """
    if (len(surface) != 2): 
        raise ValueError(f"Length of 'surface' must be 2 but was {len(surface)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(MRI_MCSIM_METADATA)
    cargs = []
    cargs.append("mri_mcsim")
    cargs.extend([
        "--o",
        top_output_dir
    ])
    cargs.extend([
        "--base",
        base_name
    ])
    cargs.extend([
        "--surface",
        *surface
    ])
    cargs.extend([
        "--nreps",
        str(num_repetitions)
    ])
    if fwhm_values is not None:
        cargs.extend([
            "--fwhm",
            *map(str, fwhm_values)
        ])
    if fwhm_max is not None:
        cargs.extend([
            "--fwhm-max",
            str(fwhm_max)
        ])
    if avg_vertex_area:
        cargs.append("--avgvtxarea")
    if random_seed is not None:
        cargs.extend([
            "--seed",
            str(random_seed)
        ])
    if label_file is not None:
        cargs.extend([
            "--label",
            execution.input_file(label_file)
        ])
    if mask_file is not None:
        cargs.extend([
            "--mask",
            execution.input_file(mask_file)
        ])
    if no_label:
        cargs.append("--no-label")
    if no_save_mask:
        cargs.append("--no-save-mask")
    if surface_name is not None:
        cargs.extend([
            "--surfname",
            surface_name
        ])
    if log_file is not None:
        cargs.extend([
            "--log",
            log_file
        ])
    if done_file is not None:
        cargs.extend([
            "--done",
            done_file
        ])
    if stop_file is not None:
        cargs.extend([
            "--stop",
            stop_file
        ])
    if save_file is not None:
        cargs.extend([
            "--save",
            save_file
        ])
    if save_iter:
        cargs.append("--save-iter")
    if subjects_dir is not None:
        cargs.extend([
            "--sd",
            subjects_dir
        ])
    if debug:
        cargs.append("--debug")
    if check_opts:
        cargs.append("--checkopts")
    if help_:
        cargs.append("--help")
    if version:
        cargs.append("--version")
    ret = MriMcsimOutputs(
        root=execution.output_file("."),
        csd_output=execution.output_file(top_output_dir + "/" + base_name + ".csd"),
        done_output=execution.output_file(top_output_dir + "/done/" + done_file) if (done_file is not None) else None,
        iteration_save=execution.output_file(top_output_dir + "/" + save_file) if (save_file is not None) else None,
        log_output=execution.output_file(top_output_dir + "/log/" + log_file) if (log_file is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MRI_MCSIM_METADATA",
    "MriMcsimOutputs",
    "mri_mcsim",
]
