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

import typing
import pathlib
from styxdefs import *

CIFTI_ESTIMATE_FWHM_METADATA = Metadata(
    id="bfd040551c3a70785cb9174fd0ff584bb1326d8a.workbench",
    name="cifti-estimate-fwhm",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiEstimateFwhmSurfaceParamsDictNoTag = typing.TypedDict('_CiftiEstimateFwhmSurfaceParamsDictNoTag', {
    "structure": str,
    "surface": InputPathType,
})
CiftiEstimateFwhmSurfaceParamsDictTagged = typing.TypedDict('CiftiEstimateFwhmSurfaceParamsDictTagged', {
    "@type": typing.Literal["surface"],
    "structure": str,
    "surface": InputPathType,
})
CiftiEstimateFwhmSurfaceParamsDict = _CiftiEstimateFwhmSurfaceParamsDictNoTag | CiftiEstimateFwhmSurfaceParamsDictTagged


_CiftiEstimateFwhmParamsDictNoTag = typing.TypedDict('_CiftiEstimateFwhmParamsDictNoTag', {
    "cifti": InputPathType,
    "surface": typing.NotRequired[list[CiftiEstimateFwhmSurfaceParamsDict] | None],
    "demean": typing.NotRequired[bool | None],
    "column": typing.NotRequired[int | None],
    "merged-volume": bool,
})
CiftiEstimateFwhmParamsDictTagged = typing.TypedDict('CiftiEstimateFwhmParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-estimate-fwhm"],
    "cifti": InputPathType,
    "surface": typing.NotRequired[list[CiftiEstimateFwhmSurfaceParamsDict] | None],
    "demean": typing.NotRequired[bool | None],
    "column": typing.NotRequired[int | None],
    "merged-volume": bool,
})
CiftiEstimateFwhmParamsDict = _CiftiEstimateFwhmParamsDictNoTag | CiftiEstimateFwhmParamsDictTagged


def cifti_estimate_fwhm_surface(
    structure: str,
    surface: InputPathType,
) -> CiftiEstimateFwhmSurfaceParamsDictTagged:
    """
    Build parameters.
    
    Args:
        structure: what structure to use this surface for.
        surface: the surface file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "surface",
        "structure": structure,
        "surface": surface,
    }
    return params


def cifti_estimate_fwhm_surface_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiEstimateFwhmSurfaceParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("structure", None) is None:
        raise StyxValidationError("`structure` must not be None")
    if not isinstance(params["structure"], str):
        raise StyxValidationError(f'`structure` has the wrong type: Received `{type(params.get("structure", None))}` expected `str`')
    if params.get("surface", None) is None:
        raise StyxValidationError("`surface` must not be None")
    if not isinstance(params["surface"], (pathlib.Path, str)):
        raise StyxValidationError(f'`surface` has the wrong type: Received `{type(params.get("surface", None))}` expected `InputPathType`')


def cifti_estimate_fwhm_surface_cargs(
    params: CiftiEstimateFwhmSurfaceParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.extend([
        "-surface",
        params.get("structure", None),
        execution.input_file(params.get("surface", None))
    ])
    return cargs


class CiftiEstimateFwhmOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiEstimateFwhmParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def cifti_estimate_fwhm_params(
    cifti: InputPathType,
    surface: list[CiftiEstimateFwhmSurfaceParamsDict] | None = None,
    demean: bool | None = None,
    column: int | None = None,
    merged_volume: bool = False,
) -> CiftiEstimateFwhmParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti: the input cifti file.
        surface: specify an input surface.
        demean: estimate for the whole file at once, not each column separately\
            \
            subtract the mean image before estimating smoothness.
        column: only output estimates for one column\
            \
            the column number.
        merged_volume: treat volume components as if they were a single\
            component.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-estimate-fwhm",
        "cifti": cifti,
        "merged-volume": merged_volume,
    }
    if surface is not None:
        params["surface"] = surface
    if demean is not None:
        params["demean"] = demean
    if column is not None:
        params["column"] = column
    return params


def cifti_estimate_fwhm_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiEstimateFwhmParamsDict` object.
    
    Args:
        params: The parameters object to validate.
    """
    if params is None or not isinstance(params, dict):
        raise StyxValidationError(f'Params object has the wrong type \'{type(params)}\'')
    if params.get("cifti", None) is None:
        raise StyxValidationError("`cifti` must not be None")
    if not isinstance(params["cifti"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti` has the wrong type: Received `{type(params.get("cifti", None))}` expected `InputPathType`')
    if params.get("surface", None) is not None:
        if not isinstance(params["surface"], list):
            raise StyxValidationError(f'`surface` has the wrong type: Received `{type(params.get("surface", None))}` expected `list[CiftiEstimateFwhmSurfaceParamsDict] | None`')
        for e in params["surface"]:
            cifti_estimate_fwhm_surface_validate(e)
    if params.get("demean", None) is not None:
        if not isinstance(params["demean"], bool):
            raise StyxValidationError(f'`demean` has the wrong type: Received `{type(params.get("demean", None))}` expected `bool | None`')
    if params.get("column", None) is not None:
        if not isinstance(params["column"], int):
            raise StyxValidationError(f'`column` has the wrong type: Received `{type(params.get("column", None))}` expected `int | None`')
    if params.get("merged-volume", False) is None:
        raise StyxValidationError("`merged-volume` must not be None")
    if not isinstance(params["merged-volume"], bool):
        raise StyxValidationError(f'`merged-volume` has the wrong type: Received `{type(params.get("merged-volume", False))}` expected `bool`')


def cifti_estimate_fwhm_cargs(
    params: CiftiEstimateFwhmParamsDict,
    execution: Execution,
) -> list[str]:
    """
    Build command-line arguments from parameters.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Command-line arguments.
    """
    cargs = []
    cargs.extend([
        "wb_command",
        "-cifti-estimate-fwhm"
    ])
    cargs.append(execution.input_file(params.get("cifti", None)))
    if params.get("surface", None) is not None:
        cargs.extend([a for c in [cifti_estimate_fwhm_surface_cargs(s, execution) for s in params.get("surface", None)] for a in c])
    if params.get("demean", None) is not None:
        cargs.extend([
            "-whole-file",
            "-demean"
        ])
    if params.get("column", None) is not None:
        cargs.extend([
            "-column",
            str(params.get("column", None))
        ])
    if params.get("merged-volume", False):
        cargs.append("-merged-volume")
    return cargs


def cifti_estimate_fwhm_outputs(
    params: CiftiEstimateFwhmParamsDict,
    execution: Execution,
) -> CiftiEstimateFwhmOutputs:
    """
    Build outputs object containing output file paths and possibly stdout/stderr.
    
    Args:
        params: The parameters.
        execution: The execution object for resolving input paths.
    Returns:
        Outputs object.
    """
    ret = CiftiEstimateFwhmOutputs(
        root=execution.output_file("."),
    )
    return ret


def cifti_estimate_fwhm_execute(
    params: CiftiEstimateFwhmParamsDict,
    runner: Runner | None = None,
) -> CiftiEstimateFwhmOutputs:
    """
    ESTIMATE FWHM SMOOTHNESS OF A CIFTI FILE.
    
    Estimate the smoothness of the components of the cifti file, printing the
    estimates to standard output. If -merged-volume is used, all voxels are used
    as a single component, rather than separated by structure.
    
    <structure> must be one of the following:
    
    CORTEX_LEFT
    CORTEX_RIGHT
    CEREBELLUM
    ACCUMBENS_LEFT
    ACCUMBENS_RIGHT
    ALL_GREY_MATTER
    ALL_WHITE_MATTER
    AMYGDALA_LEFT
    AMYGDALA_RIGHT
    BRAIN_STEM
    CAUDATE_LEFT
    CAUDATE_RIGHT
    CEREBELLAR_WHITE_MATTER_LEFT
    CEREBELLAR_WHITE_MATTER_RIGHT
    CEREBELLUM_LEFT
    CEREBELLUM_RIGHT
    CEREBRAL_WHITE_MATTER_LEFT
    CEREBRAL_WHITE_MATTER_RIGHT
    CORTEX
    DIENCEPHALON_VENTRAL_LEFT
    DIENCEPHALON_VENTRAL_RIGHT
    HIPPOCAMPUS_LEFT
    HIPPOCAMPUS_RIGHT
    HIPPOCAMPUS_DENTATE_LEFT
    HIPPOCAMPUS_DENTATE_RIGHT
    INVALID
    OTHER
    OTHER_GREY_MATTER
    OTHER_WHITE_MATTER
    PALLIDUM_LEFT
    PALLIDUM_RIGHT
    PUTAMEN_LEFT
    PUTAMEN_RIGHT
    THALAMUS_LEFT
    THALAMUS_RIGHT.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiEstimateFwhmOutputs`).
    """
    cifti_estimate_fwhm_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_ESTIMATE_FWHM_METADATA)
    params = execution.params(params)
    cargs = cifti_estimate_fwhm_cargs(params, execution)
    ret = cifti_estimate_fwhm_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_estimate_fwhm(
    cifti: InputPathType,
    surface: list[CiftiEstimateFwhmSurfaceParamsDict] | None = None,
    demean: bool | None = None,
    column: int | None = None,
    merged_volume: bool = False,
    runner: Runner | None = None,
) -> CiftiEstimateFwhmOutputs:
    """
    ESTIMATE FWHM SMOOTHNESS OF A CIFTI FILE.
    
    Estimate the smoothness of the components of the cifti file, printing the
    estimates to standard output. If -merged-volume is used, all voxels are used
    as a single component, rather than separated by structure.
    
    <structure> must be one of the following:
    
    CORTEX_LEFT
    CORTEX_RIGHT
    CEREBELLUM
    ACCUMBENS_LEFT
    ACCUMBENS_RIGHT
    ALL_GREY_MATTER
    ALL_WHITE_MATTER
    AMYGDALA_LEFT
    AMYGDALA_RIGHT
    BRAIN_STEM
    CAUDATE_LEFT
    CAUDATE_RIGHT
    CEREBELLAR_WHITE_MATTER_LEFT
    CEREBELLAR_WHITE_MATTER_RIGHT
    CEREBELLUM_LEFT
    CEREBELLUM_RIGHT
    CEREBRAL_WHITE_MATTER_LEFT
    CEREBRAL_WHITE_MATTER_RIGHT
    CORTEX
    DIENCEPHALON_VENTRAL_LEFT
    DIENCEPHALON_VENTRAL_RIGHT
    HIPPOCAMPUS_LEFT
    HIPPOCAMPUS_RIGHT
    HIPPOCAMPUS_DENTATE_LEFT
    HIPPOCAMPUS_DENTATE_RIGHT
    INVALID
    OTHER
    OTHER_GREY_MATTER
    OTHER_WHITE_MATTER
    PALLIDUM_LEFT
    PALLIDUM_RIGHT
    PUTAMEN_LEFT
    PUTAMEN_RIGHT
    THALAMUS_LEFT
    THALAMUS_RIGHT.
    
    Args:
        cifti: the input cifti file.
        surface: specify an input surface.
        demean: estimate for the whole file at once, not each column separately\
            \
            subtract the mean image before estimating smoothness.
        column: only output estimates for one column\
            \
            the column number.
        merged_volume: treat volume components as if they were a single\
            component.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiEstimateFwhmOutputs`).
    """
    params = cifti_estimate_fwhm_params(
        cifti=cifti,
        surface=surface,
        demean=demean,
        column=column,
        merged_volume=merged_volume,
    )
    return cifti_estimate_fwhm_execute(params, runner)


__all__ = [
    "CIFTI_ESTIMATE_FWHM_METADATA",
    "CiftiEstimateFwhmOutputs",
    "CiftiEstimateFwhmParamsDict",
    "CiftiEstimateFwhmParamsDictTagged",
    "CiftiEstimateFwhmSurfaceParamsDict",
    "CiftiEstimateFwhmSurfaceParamsDictTagged",
    "cifti_estimate_fwhm",
    "cifti_estimate_fwhm_execute",
    "cifti_estimate_fwhm_params",
    "cifti_estimate_fwhm_surface",
]
