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

import typing
import pathlib
from styxdefs import *

SET_STRUCTURE_METADATA = Metadata(
    id="3f017d3648fe7b335b883d3f5dcd0884cd807980.workbench",
    name="set-structure",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SetStructureParamsDictNoTag = typing.TypedDict('_SetStructureParamsDictNoTag', {
    "data-file": str,
    "structure": str,
    "secondary type": typing.NotRequired[str | None],
    "type": typing.NotRequired[str | None],
})
SetStructureParamsDictTagged = typing.TypedDict('SetStructureParamsDictTagged', {
    "@type": typing.Literal["workbench/set-structure"],
    "data-file": str,
    "structure": str,
    "secondary type": typing.NotRequired[str | None],
    "type": typing.NotRequired[str | None],
})
SetStructureParamsDict = _SetStructureParamsDictNoTag | SetStructureParamsDictTagged


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


def set_structure_params(
    data_file: str,
    structure: str,
    secondary_type: str | None = None,
    type_: str | None = None,
) -> SetStructureParamsDictTagged:
    """
    Build parameters.
    
    Args:
        data_file: the file to set the structure of.
        structure: the structure to set the file to.
        secondary_type: set the secondary type of a surface (only used if file\
            is a surface file)\
            \
            name of surface secondary type.
        type_: set the type of a surface (only used if file is a surface file)\
            \
            name of surface type.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/set-structure",
        "data-file": data_file,
        "structure": structure,
    }
    if secondary_type is not None:
        params["secondary type"] = secondary_type
    if type_ is not None:
        params["type"] = type_
    return params


def set_structure_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SetStructureParamsDict` 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("data-file", None) is None:
        raise StyxValidationError("`data-file` must not be None")
    if not isinstance(params["data-file"], str):
        raise StyxValidationError(f'`data-file` has the wrong type: Received `{type(params.get("data-file", None))}` expected `str`')
    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("secondary type", None) is not None:
        if not isinstance(params["secondary type"], str):
            raise StyxValidationError(f'`secondary type` has the wrong type: Received `{type(params.get("secondary type", None))}` expected `str | None`')
    if params.get("type", None) is not None:
        if not isinstance(params["type"], str):
            raise StyxValidationError(f'`type` has the wrong type: Received `{type(params.get("type", None))}` expected `str | None`')


def set_structure_cargs(
    params: SetStructureParamsDict,
    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",
        "-set-structure"
    ])
    cargs.append(params.get("data-file", None))
    cargs.append(params.get("structure", None))
    if params.get("secondary type", None) is not None:
        cargs.extend([
            "-surface-secondary-type",
            params.get("secondary type", None)
        ])
    if params.get("type", None) is not None:
        cargs.extend([
            "-surface-type",
            params.get("type", None)
        ])
    return cargs


def set_structure_outputs(
    params: SetStructureParamsDict,
    execution: Execution,
) -> SetStructureOutputs:
    """
    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 = SetStructureOutputs(
        root=execution.output_file("."),
    )
    return ret


def set_structure_execute(
    params: SetStructureParamsDict,
    runner: Runner | None = None,
) -> SetStructureOutputs:
    """
    SET STRUCTURE OF A DATA FILE.
    
    The existing file is modified and rewritten to the same filename. Valid
    values for the structure name are:
    
    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
    
    Valid names for the surface type are:
    
    UNKNOWN
    RECONSTRUCTION
    ANATOMICAL
    INFLATED
    VERY_INFLATED
    SPHERICAL
    SEMI_SPHERICAL
    ELLIPSOID
    FLAT
    HULL
    
    Valid names for the surface secondary type are:
    
    INVALID
    GRAY_WHITE
    MIDTHICKNESS
    PIAL
    INNER
    OUTER
    .
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SetStructureOutputs`).
    """
    set_structure_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SET_STRUCTURE_METADATA)
    params = execution.params(params)
    cargs = set_structure_cargs(params, execution)
    ret = set_structure_outputs(params, execution)
    execution.run(cargs)
    return ret


def set_structure(
    data_file: str,
    structure: str,
    secondary_type: str | None = None,
    type_: str | None = None,
    runner: Runner | None = None,
) -> SetStructureOutputs:
    """
    SET STRUCTURE OF A DATA FILE.
    
    The existing file is modified and rewritten to the same filename. Valid
    values for the structure name are:
    
    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
    
    Valid names for the surface type are:
    
    UNKNOWN
    RECONSTRUCTION
    ANATOMICAL
    INFLATED
    VERY_INFLATED
    SPHERICAL
    SEMI_SPHERICAL
    ELLIPSOID
    FLAT
    HULL
    
    Valid names for the surface secondary type are:
    
    INVALID
    GRAY_WHITE
    MIDTHICKNESS
    PIAL
    INNER
    OUTER
    .
    
    Args:
        data_file: the file to set the structure of.
        structure: the structure to set the file to.
        secondary_type: set the secondary type of a surface (only used if file\
            is a surface file)\
            \
            name of surface secondary type.
        type_: set the type of a surface (only used if file is a surface file)\
            \
            name of surface type.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SetStructureOutputs`).
    """
    params = set_structure_params(
        data_file=data_file,
        structure=structure,
        secondary_type=secondary_type,
        type_=type_,
    )
    return set_structure_execute(params, runner)


__all__ = [
    "SET_STRUCTURE_METADATA",
    "SetStructureOutputs",
    "SetStructureParamsDict",
    "SetStructureParamsDictTagged",
    "set_structure",
    "set_structure_execute",
    "set_structure_params",
]
