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

import typing
import pathlib
from styxdefs import *

CIFTI_EXPORT_DENSE_MAPPING_METADATA = Metadata(
    id="caf8dad8ae4809da9a7eb9ca3301a06449390ae2.workbench",
    name="cifti-export-dense-mapping",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiExportDenseMappingVolumeAllParamsDictNoTag = typing.TypedDict('_CiftiExportDenseMappingVolumeAllParamsDictNoTag', {
    "text-out": str,
    "structure": bool,
    "no-cifti-index": bool,
})
CiftiExportDenseMappingVolumeAllParamsDictTagged = typing.TypedDict('CiftiExportDenseMappingVolumeAllParamsDictTagged', {
    "@type": typing.Literal["volume-all"],
    "text-out": str,
    "structure": bool,
    "no-cifti-index": bool,
})
CiftiExportDenseMappingVolumeAllParamsDict = _CiftiExportDenseMappingVolumeAllParamsDictNoTag | CiftiExportDenseMappingVolumeAllParamsDictTagged


_CiftiExportDenseMappingSurfaceParamsDictNoTag = typing.TypedDict('_CiftiExportDenseMappingSurfaceParamsDictNoTag', {
    "structure": str,
    "text-out": str,
    "no-cifti-index": bool,
})
CiftiExportDenseMappingSurfaceParamsDictTagged = typing.TypedDict('CiftiExportDenseMappingSurfaceParamsDictTagged', {
    "@type": typing.Literal["surface"],
    "structure": str,
    "text-out": str,
    "no-cifti-index": bool,
})
CiftiExportDenseMappingSurfaceParamsDict = _CiftiExportDenseMappingSurfaceParamsDictNoTag | CiftiExportDenseMappingSurfaceParamsDictTagged


_CiftiExportDenseMappingVolumeParamsDictNoTag = typing.TypedDict('_CiftiExportDenseMappingVolumeParamsDictNoTag', {
    "structure": str,
    "text-out": str,
    "no-cifti-index": bool,
})
CiftiExportDenseMappingVolumeParamsDictTagged = typing.TypedDict('CiftiExportDenseMappingVolumeParamsDictTagged', {
    "@type": typing.Literal["volume"],
    "structure": str,
    "text-out": str,
    "no-cifti-index": bool,
})
CiftiExportDenseMappingVolumeParamsDict = _CiftiExportDenseMappingVolumeParamsDictNoTag | CiftiExportDenseMappingVolumeParamsDictTagged


_CiftiExportDenseMappingParamsDictNoTag = typing.TypedDict('_CiftiExportDenseMappingParamsDictNoTag', {
    "cifti": InputPathType,
    "direction": str,
    "volume-all": typing.NotRequired[CiftiExportDenseMappingVolumeAllParamsDict | None],
    "surface": typing.NotRequired[list[CiftiExportDenseMappingSurfaceParamsDict] | None],
    "volume": typing.NotRequired[list[CiftiExportDenseMappingVolumeParamsDict] | None],
})
CiftiExportDenseMappingParamsDictTagged = typing.TypedDict('CiftiExportDenseMappingParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-export-dense-mapping"],
    "cifti": InputPathType,
    "direction": str,
    "volume-all": typing.NotRequired[CiftiExportDenseMappingVolumeAllParamsDict | None],
    "surface": typing.NotRequired[list[CiftiExportDenseMappingSurfaceParamsDict] | None],
    "volume": typing.NotRequired[list[CiftiExportDenseMappingVolumeParamsDict] | None],
})
CiftiExportDenseMappingParamsDict = _CiftiExportDenseMappingParamsDictNoTag | CiftiExportDenseMappingParamsDictTagged


def cifti_export_dense_mapping_volume_all(
    text_out: str,
    structure: bool = False,
    no_cifti_index: bool = False,
) -> CiftiExportDenseMappingVolumeAllParamsDictTagged:
    """
    Build parameters.
    
    Args:
        text_out: output - the output text file.
        structure: write the structure each voxel belongs to in the output file.
        no_cifti_index: don't write the cifti index in the output file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "volume-all",
        "text-out": text_out,
        "structure": structure,
        "no-cifti-index": no_cifti_index,
    }
    return params


def cifti_export_dense_mapping_volume_all_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiExportDenseMappingVolumeAllParamsDict` 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("text-out", None) is None:
        raise StyxValidationError("`text-out` must not be None")
    if not isinstance(params["text-out"], str):
        raise StyxValidationError(f'`text-out` has the wrong type: Received `{type(params.get("text-out", None))}` expected `str`')
    if params.get("structure", False) is None:
        raise StyxValidationError("`structure` must not be None")
    if not isinstance(params["structure"], bool):
        raise StyxValidationError(f'`structure` has the wrong type: Received `{type(params.get("structure", False))}` expected `bool`')
    if params.get("no-cifti-index", False) is None:
        raise StyxValidationError("`no-cifti-index` must not be None")
    if not isinstance(params["no-cifti-index"], bool):
        raise StyxValidationError(f'`no-cifti-index` has the wrong type: Received `{type(params.get("no-cifti-index", False))}` expected `bool`')


def cifti_export_dense_mapping_volume_all_cargs(
    params: CiftiExportDenseMappingVolumeAllParamsDict,
    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([
        "-volume-all",
        params.get("text-out", None)
    ])
    if params.get("structure", False):
        cargs.append("-structure")
    if params.get("no-cifti-index", False):
        cargs.append("-no-cifti-index")
    return cargs


def cifti_export_dense_mapping_surface(
    structure: str,
    text_out: str,
    no_cifti_index: bool = False,
) -> CiftiExportDenseMappingSurfaceParamsDictTagged:
    """
    Build parameters.
    
    Args:
        structure: the structure to output.
        text_out: output - the output text file.
        no_cifti_index: don't write the cifti index in the output file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "surface",
        "structure": structure,
        "text-out": text_out,
        "no-cifti-index": no_cifti_index,
    }
    return params


def cifti_export_dense_mapping_surface_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiExportDenseMappingSurfaceParamsDict` 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("text-out", None) is None:
        raise StyxValidationError("`text-out` must not be None")
    if not isinstance(params["text-out"], str):
        raise StyxValidationError(f'`text-out` has the wrong type: Received `{type(params.get("text-out", None))}` expected `str`')
    if params.get("no-cifti-index", False) is None:
        raise StyxValidationError("`no-cifti-index` must not be None")
    if not isinstance(params["no-cifti-index"], bool):
        raise StyxValidationError(f'`no-cifti-index` has the wrong type: Received `{type(params.get("no-cifti-index", False))}` expected `bool`')


def cifti_export_dense_mapping_surface_cargs(
    params: CiftiExportDenseMappingSurfaceParamsDict,
    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),
        params.get("text-out", None)
    ])
    if params.get("no-cifti-index", False):
        cargs.append("-no-cifti-index")
    return cargs


def cifti_export_dense_mapping_volume(
    structure: str,
    text_out: str,
    no_cifti_index: bool = False,
) -> CiftiExportDenseMappingVolumeParamsDictTagged:
    """
    Build parameters.
    
    Args:
        structure: the structure to output.
        text_out: output - the output text file.
        no_cifti_index: don't write the cifti index in the output file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "volume",
        "structure": structure,
        "text-out": text_out,
        "no-cifti-index": no_cifti_index,
    }
    return params


def cifti_export_dense_mapping_volume_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiExportDenseMappingVolumeParamsDict` 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("text-out", None) is None:
        raise StyxValidationError("`text-out` must not be None")
    if not isinstance(params["text-out"], str):
        raise StyxValidationError(f'`text-out` has the wrong type: Received `{type(params.get("text-out", None))}` expected `str`')
    if params.get("no-cifti-index", False) is None:
        raise StyxValidationError("`no-cifti-index` must not be None")
    if not isinstance(params["no-cifti-index"], bool):
        raise StyxValidationError(f'`no-cifti-index` has the wrong type: Received `{type(params.get("no-cifti-index", False))}` expected `bool`')


def cifti_export_dense_mapping_volume_cargs(
    params: CiftiExportDenseMappingVolumeParamsDict,
    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([
        "-volume",
        params.get("structure", None),
        params.get("text-out", None)
    ])
    if params.get("no-cifti-index", False):
        cargs.append("-no-cifti-index")
    return cargs


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


def cifti_export_dense_mapping_params(
    cifti: InputPathType,
    direction: str,
    volume_all: CiftiExportDenseMappingVolumeAllParamsDict | None = None,
    surface: list[CiftiExportDenseMappingSurfaceParamsDict] | None = None,
    volume: list[CiftiExportDenseMappingVolumeParamsDict] | None = None,
) -> CiftiExportDenseMappingParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti: the cifti file.
        direction: which direction to export the mapping from, ROW or COLUMN.
        volume_all: export the the mapping of all voxels.
        surface: export the the mapping of one surface structure.
        volume: export the the mapping of one volume structure.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-export-dense-mapping",
        "cifti": cifti,
        "direction": direction,
    }
    if volume_all is not None:
        params["volume-all"] = volume_all
    if surface is not None:
        params["surface"] = surface
    if volume is not None:
        params["volume"] = volume
    return params


def cifti_export_dense_mapping_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiExportDenseMappingParamsDict` 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("direction", None) is None:
        raise StyxValidationError("`direction` must not be None")
    if not isinstance(params["direction"], str):
        raise StyxValidationError(f'`direction` has the wrong type: Received `{type(params.get("direction", None))}` expected `str`')
    if params.get("volume-all", None) is not None:
        cifti_export_dense_mapping_volume_all_validate(params["volume-all"])
    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[CiftiExportDenseMappingSurfaceParamsDict] | None`')
        for e in params["surface"]:
            cifti_export_dense_mapping_surface_validate(e)
    if params.get("volume", None) is not None:
        if not isinstance(params["volume"], list):
            raise StyxValidationError(f'`volume` has the wrong type: Received `{type(params.get("volume", None))}` expected `list[CiftiExportDenseMappingVolumeParamsDict] | None`')
        for e in params["volume"]:
            cifti_export_dense_mapping_volume_validate(e)


def cifti_export_dense_mapping_cargs(
    params: CiftiExportDenseMappingParamsDict,
    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-export-dense-mapping"
    ])
    cargs.append(execution.input_file(params.get("cifti", None)))
    cargs.append(params.get("direction", None))
    if params.get("volume-all", None) is not None or params.get("surface", None) is not None or params.get("volume", None) is not None:
        cargs.extend([
            *(cifti_export_dense_mapping_volume_all_cargs(params.get("volume-all", None), execution) if (params.get("volume-all", None) is not None) else []),
            *([a for c in [cifti_export_dense_mapping_surface_cargs(s, execution) for s in params.get("surface", None)] for a in c] if (params.get("surface", None) is not None) else []),
            *([a for c in [cifti_export_dense_mapping_volume_cargs(s, execution) for s in params.get("volume", None)] for a in c] if (params.get("volume", None) is not None) else [])
        ])
    return cargs


def cifti_export_dense_mapping_outputs(
    params: CiftiExportDenseMappingParamsDict,
    execution: Execution,
) -> CiftiExportDenseMappingOutputs:
    """
    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 = CiftiExportDenseMappingOutputs(
        root=execution.output_file("."),
    )
    return ret


def cifti_export_dense_mapping_execute(
    params: CiftiExportDenseMappingParamsDict,
    runner: Runner | None = None,
) -> CiftiExportDenseMappingOutputs:
    """
    WRITE INDEX TO ELEMENT MAPPING AS TEXT.
    
    This command produces text files that describe the mapping from cifti
    indices to surface vertices or voxels. All indices are zero-based. The
    default format for -surface is lines of the form:
    
    <cifti-index> <vertex>
    
    The default format for -volume and -volume-all is lines of the form:
    
    <cifti-index> <i> <j> <k>
    
    For each <structure> argument, use one of the following strings:
    
    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 `CiftiExportDenseMappingOutputs`).
    """
    cifti_export_dense_mapping_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_EXPORT_DENSE_MAPPING_METADATA)
    params = execution.params(params)
    cargs = cifti_export_dense_mapping_cargs(params, execution)
    ret = cifti_export_dense_mapping_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_export_dense_mapping(
    cifti: InputPathType,
    direction: str,
    volume_all: CiftiExportDenseMappingVolumeAllParamsDict | None = None,
    surface: list[CiftiExportDenseMappingSurfaceParamsDict] | None = None,
    volume: list[CiftiExportDenseMappingVolumeParamsDict] | None = None,
    runner: Runner | None = None,
) -> CiftiExportDenseMappingOutputs:
    """
    WRITE INDEX TO ELEMENT MAPPING AS TEXT.
    
    This command produces text files that describe the mapping from cifti
    indices to surface vertices or voxels. All indices are zero-based. The
    default format for -surface is lines of the form:
    
    <cifti-index> <vertex>
    
    The default format for -volume and -volume-all is lines of the form:
    
    <cifti-index> <i> <j> <k>
    
    For each <structure> argument, use one of the following strings:
    
    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 cifti file.
        direction: which direction to export the mapping from, ROW or COLUMN.
        volume_all: export the the mapping of all voxels.
        surface: export the the mapping of one surface structure.
        volume: export the the mapping of one volume structure.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiExportDenseMappingOutputs`).
    """
    params = cifti_export_dense_mapping_params(
        cifti=cifti,
        direction=direction,
        volume_all=volume_all,
        surface=surface,
        volume=volume,
    )
    return cifti_export_dense_mapping_execute(params, runner)


__all__ = [
    "CIFTI_EXPORT_DENSE_MAPPING_METADATA",
    "CiftiExportDenseMappingOutputs",
    "CiftiExportDenseMappingParamsDict",
    "CiftiExportDenseMappingParamsDictTagged",
    "CiftiExportDenseMappingSurfaceParamsDict",
    "CiftiExportDenseMappingSurfaceParamsDictTagged",
    "CiftiExportDenseMappingVolumeAllParamsDict",
    "CiftiExportDenseMappingVolumeAllParamsDictTagged",
    "CiftiExportDenseMappingVolumeParamsDict",
    "CiftiExportDenseMappingVolumeParamsDictTagged",
    "cifti_export_dense_mapping",
    "cifti_export_dense_mapping_execute",
    "cifti_export_dense_mapping_params",
    "cifti_export_dense_mapping_surface",
    "cifti_export_dense_mapping_volume",
    "cifti_export_dense_mapping_volume_all",
]
