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

import typing
import pathlib
from styxdefs import *
import dataclasses

MIDEFACE_METADATA = Metadata(
    id="38b6a923ce22638bd0e6fc77f68e3ac76360f9d7.boutiques",
    name="mideface",
    package="freesurfer",
    container_image_tag="freesurfer/freesurfer:7.4.1",
)


class MidefaceOutputs(typing.NamedTuple):
    """
    Output object returned when calling `mideface(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    defaced_output: OutputPathType
    """Defaced output volume"""
    facemask_output: OutputPathType | None
    """Applied facemask file"""


def mideface(
    input_volume: InputPathType,
    output_volume: InputPathType,
    facemask: InputPathType | None = None,
    output_dir: str | None = None,
    exclusion_mask: InputPathType | None = None,
    samseg_ndilations: float | None = None,
    samseg_json: str | None = None,
    init_reg: InputPathType | None = None,
    synthseg_ndilations: float | None = None,
    fill_const: list[float] | None = None,
    fhi: float | None = None,
    code_: str | None = None,
    image_convert: str | None = None,
    threads: float | None = None,
    display_no: float | None = None,
    apply_volume: str | None = None,
    check_volume: InputPathType | None = None,
    check_output_file: InputPathType | None = None,
    output_format: str | None = None,
    runner: Runner | None = None,
) -> MidefaceOutputs:
    """
    Minimally invasive defacing tool.
    
    Author: FreeSurfer Developers
    
    URL: https://github.com/freesurfer/freesurfer
    
    Args:
        input_volume: Volume to deface.
        output_volume: Defaced output volume.
        facemask: Facemask to apply.
        output_dir: Directory for outputs, activates PostHeadSurf.
        exclusion_mask: Mask to exclude certain regions from defacing.
        samseg_ndilations: Number of dilations for Samseg segmentation.
        samseg_json: JSON configuration for Samseg.
        init_reg: Initial registration file for Samseg.
        synthseg_ndilations: Number of dilations for Synthseg segmentation.
        fill_const: Constants for filling regions.
        fhi: FHI value for MRIchangeType().
        code_: Embed code name in pictures.
        image_convert: Path to ImageMagick convert binary for pictures.
        threads: Number of threads to use.
        display_no: Xvfb display number for taking pictures.
        apply_volume: Apply midface output to a second volume.
        check_volume: Volume to check if defaced.
        check_output_file: Optional output file for check result.
        output_format: Output file format.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `MidefaceOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(MIDEFACE_METADATA)
    cargs = []
    cargs.append("mideface")
    cargs.extend([
        "--i",
        execution.input_file(input_volume)
    ])
    cargs.extend([
        "--o",
        execution.input_file(output_volume)
    ])
    if facemask is not None:
        cargs.extend([
            "--facemask",
            execution.input_file(facemask)
        ])
    if output_dir is not None:
        cargs.extend([
            "--odir",
            output_dir
        ])
    if exclusion_mask is not None:
        cargs.extend([
            "--xmask",
            execution.input_file(exclusion_mask)
        ])
    if samseg_ndilations is not None:
        cargs.extend([
            "--xmask-samseg",
            str(samseg_ndilations)
        ])
    if samseg_json is not None:
        cargs.extend([
            "--samseg-json",
            samseg_json
        ])
    if init_reg is not None:
        cargs.extend([
            "--init-reg",
            execution.input_file(init_reg)
        ])
    if synthseg_ndilations is not None:
        cargs.extend([
            "--xmask-synthseg",
            str(synthseg_ndilations)
        ])
    if fill_const is not None:
        cargs.extend([
            "--fill-const",
            *map(str, fill_const)
        ])
    if fhi is not None:
        cargs.extend([
            "--fhi",
            str(fhi)
        ])
    if code_ is not None:
        cargs.extend([
            "--code",
            code_
        ])
    if image_convert is not None:
        cargs.extend([
            "--imconvert",
            image_convert
        ])
    if threads is not None:
        cargs.extend([
            "--threads",
            str(threads)
        ])
    if display_no is not None:
        cargs.extend([
            "--display",
            str(display_no)
        ])
    if apply_volume is not None:
        cargs.extend([
            "--apply",
            apply_volume
        ])
    if check_volume is not None:
        cargs.extend([
            "--check",
            execution.input_file(check_volume)
        ])
    if check_output_file is not None:
        cargs.extend([
            "--check",
            execution.input_file(check_output_file)
        ])
    if output_format is not None:
        cargs.extend([
            "--nii --nii.gz --mgz",
            output_format
        ])
    ret = MidefaceOutputs(
        root=execution.output_file("."),
        defaced_output=execution.output_file(pathlib.Path(output_volume).name),
        facemask_output=execution.output_file(pathlib.Path(facemask).name) if (facemask is not None) else None,
    )
    execution.run(cargs)
    return ret


__all__ = [
    "MIDEFACE_METADATA",
    "MidefaceOutputs",
    "mideface",
]
