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

import typing
import pathlib
from styxdefs import *
import dataclasses

BBMASK_METADATA = Metadata(
    id="064153f645343fa44a6da922e9a35232f8ea8522.boutiques",
    name="bbmask",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class BbmaskOutputs(typing.NamedTuple):
    """
    Output object returned when calling `bbmask(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    mask_output_file: OutputPathType
    """Output mask volume"""
    src_output_file: OutputPathType
    """Output reduced volume(s)"""
    registration_output_file: OutputPathType
    """Output registration file"""
    regheader_output_file: OutputPathType
    """Output registration file from regheader"""
    sub2src_output_file: OutputPathType
    """Output file for sub2src registration"""


def bbmask(
    mask: list[InputPathType],
    src_volumes: list[InputPathType] | None = None,
    npad: float | None = None,
    registration: list[InputPathType] | None = None,
    regheader: InputPathType | None = None,
    sub2src: InputPathType | None = None,
    runner: Runner | None = None,
) -> BbmaskOutputs:
    """
    Tool to create a volume with a smaller field of view by creating a bounding box
    that encompasses a mask.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        mask: Input and output for the mask volume.
        src_volumes: Input and output volumes to be reduced to the bounding\
            box.
        npad: Number of voxels to expand the bounding box.
        registration: Input and output registration files.
        regheader: Output registration file from header.
        sub2src: Output file for sub-source registration.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BbmaskOutputs`).
    """
    if (len(mask) != 2): 
        raise ValueError(f"Length of 'mask' must be 2 but was {len(mask)}")
    if src_volumes is not None and not (2 <= len(src_volumes)): 
        raise ValueError(f"Length of 'src_volumes' must be greater than 2 but was {len(src_volumes)}")
    if registration is not None and (len(registration) != 2): 
        raise ValueError(f"Length of 'registration' must be 2 but was {len(registration)}")
    runner = runner or get_global_runner()
    execution = runner.start_execution(BBMASK_METADATA)
    cargs = []
    cargs.append("bbmask")
    cargs.extend([
        "--mask",
        *[execution.input_file(f) for f in mask]
    ])
    if src_volumes is not None:
        cargs.extend([
            "--src",
            *[execution.input_file(f) for f in src_volumes]
        ])
    if npad is not None:
        cargs.extend([
            "--npad",
            str(npad)
        ])
    if registration is not None:
        cargs.extend([
            "--reg",
            *[execution.input_file(f) for f in registration]
        ])
    if regheader is not None:
        cargs.extend([
            "--regheader",
            execution.input_file(regheader)
        ])
    if sub2src is not None:
        cargs.extend([
            "--sub2src",
            execution.input_file(sub2src)
        ])
    ret = BbmaskOutputs(
        root=execution.output_file("."),
        mask_output_file=execution.output_file("[MASK_OUTPUT]"),
        src_output_file=execution.output_file("[SRC_OUTPUT]"),
        registration_output_file=execution.output_file("[REG_OUTPUT]"),
        regheader_output_file=execution.output_file("[REG_HEADER_OUTPUT]"),
        sub2src_output_file=execution.output_file("[SUB2SRC_OUTPUT]"),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "BBMASK_METADATA",
    "BbmaskOutputs",
    "bbmask",
]
