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

import typing
import pathlib
from styxdefs import *

CIFTI_RESTRICT_DENSE_MAP_METADATA = Metadata(
    id="15d326c1749b72cd350d3064369db0c366e4f1b4.workbench",
    name="cifti-restrict-dense-map",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiRestrictDenseMapParamsDictNoTag = typing.TypedDict('_CiftiRestrictDenseMapParamsDictNoTag', {
    "cifti-in": InputPathType,
    "direction": str,
    "cifti-out": str,
    "roi-vol": typing.NotRequired[InputPathType | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
    "roi-cifti": typing.NotRequired[InputPathType | None],
})
CiftiRestrictDenseMapParamsDictTagged = typing.TypedDict('CiftiRestrictDenseMapParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-restrict-dense-map"],
    "cifti-in": InputPathType,
    "direction": str,
    "cifti-out": str,
    "roi-vol": typing.NotRequired[InputPathType | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
    "roi-metric": typing.NotRequired[InputPathType | None],
    "roi-cifti": typing.NotRequired[InputPathType | None],
})
CiftiRestrictDenseMapParamsDict = _CiftiRestrictDenseMapParamsDictNoTag | CiftiRestrictDenseMapParamsDictTagged


class CiftiRestrictDenseMapOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiRestrictDenseMapParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    cifti_out: OutputPathType
    """the output cifti"""


def cifti_restrict_dense_map_params(
    cifti_in: InputPathType,
    direction: str,
    cifti_out: str,
    roi_vol: InputPathType | None = None,
    roi_metric: InputPathType | None = None,
    roi_metric_: InputPathType | None = None,
    roi_metric_2: InputPathType | None = None,
    roi_cifti: InputPathType | None = None,
) -> CiftiRestrictDenseMapParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: the input cifti.
        direction: which dimension to change the mapping on (integer, 'ROW', or\
            'COLUMN').
        cifti_out: the output cifti.
        roi_vol: voxels to use\
            \
            the roi volume file.
        roi_metric: vertices to use from cerebellum\
            \
            the cerebellum roi as a metric file.
        roi_metric_: vertices to use from right hemisphere\
            \
            the right roi as a metric file.
        roi_metric_2: vertices to use from left hemisphere\
            \
            the left roi as a metric file.
        roi_cifti: cifti file containing combined rois\
            \
            the rois as a cifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-restrict-dense-map",
        "cifti-in": cifti_in,
        "direction": direction,
        "cifti-out": cifti_out,
    }
    if roi_vol is not None:
        params["roi-vol"] = roi_vol
    if roi_metric is not None:
        params["roi-metric"] = roi_metric
    if roi_metric_ is not None:
        params["roi-metric"] = roi_metric_
    if roi_metric_2 is not None:
        params["roi-metric"] = roi_metric_2
    if roi_cifti is not None:
        params["roi-cifti"] = roi_cifti
    return params


def cifti_restrict_dense_map_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiRestrictDenseMapParamsDict` 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-in", None) is None:
        raise StyxValidationError("`cifti-in` must not be None")
    if not isinstance(params["cifti-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti-in` has the wrong type: Received `{type(params.get("cifti-in", 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("cifti-out", None) is None:
        raise StyxValidationError("`cifti-out` must not be None")
    if not isinstance(params["cifti-out"], str):
        raise StyxValidationError(f'`cifti-out` has the wrong type: Received `{type(params.get("cifti-out", None))}` expected `str`')
    if params.get("roi-vol", None) is not None:
        if not isinstance(params["roi-vol"], (pathlib.Path, str)):
            raise StyxValidationError(f'`roi-vol` has the wrong type: Received `{type(params.get("roi-vol", None))}` expected `InputPathType | None`')
    if params.get("roi-metric", None) is not None:
        if not isinstance(params["roi-metric"], (pathlib.Path, str)):
            raise StyxValidationError(f'`roi-metric` has the wrong type: Received `{type(params.get("roi-metric", None))}` expected `InputPathType | None`')
    if params.get("roi-metric", None) is not None:
        if not isinstance(params["roi-metric"], (pathlib.Path, str)):
            raise StyxValidationError(f'`roi-metric` has the wrong type: Received `{type(params.get("roi-metric", None))}` expected `InputPathType | None`')
    if params.get("roi-metric", None) is not None:
        if not isinstance(params["roi-metric"], (pathlib.Path, str)):
            raise StyxValidationError(f'`roi-metric` has the wrong type: Received `{type(params.get("roi-metric", None))}` expected `InputPathType | None`')
    if params.get("roi-cifti", None) is not None:
        if not isinstance(params["roi-cifti"], (pathlib.Path, str)):
            raise StyxValidationError(f'`roi-cifti` has the wrong type: Received `{type(params.get("roi-cifti", None))}` expected `InputPathType | None`')


def cifti_restrict_dense_map_cargs(
    params: CiftiRestrictDenseMapParamsDict,
    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-restrict-dense-map"
    ])
    cargs.append(execution.input_file(params.get("cifti-in", None)))
    cargs.append(params.get("direction", None))
    cargs.append(params.get("cifti-out", None))
    if params.get("roi-vol", None) is not None:
        cargs.extend([
            "-vol-roi",
            execution.input_file(params.get("roi-vol", None))
        ])
    if params.get("roi-metric", None) is not None:
        cargs.extend([
            "-cerebellum-roi",
            execution.input_file(params.get("roi-metric", None))
        ])
    if params.get("roi-metric", None) is not None:
        cargs.extend([
            "-right-roi",
            execution.input_file(params.get("roi-metric", None))
        ])
    if params.get("roi-metric", None) is not None:
        cargs.extend([
            "-left-roi",
            execution.input_file(params.get("roi-metric", None))
        ])
    if params.get("roi-cifti", None) is not None:
        cargs.extend([
            "-cifti-roi",
            execution.input_file(params.get("roi-cifti", None))
        ])
    return cargs


def cifti_restrict_dense_map_outputs(
    params: CiftiRestrictDenseMapParamsDict,
    execution: Execution,
) -> CiftiRestrictDenseMapOutputs:
    """
    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 = CiftiRestrictDenseMapOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(params.get("cifti-out", None)),
    )
    return ret


def cifti_restrict_dense_map_execute(
    params: CiftiRestrictDenseMapParamsDict,
    runner: Runner | None = None,
) -> CiftiRestrictDenseMapOutputs:
    """
    EXCLUDE BRAINORDINATES FROM A CIFTI FILE.
    
    Writes a modified version of <cifti-in>, where all brainordinates outside
    the specified roi(s) are removed from the file. The direction can be either
    an integer starting from 1, or the strings 'ROW' or 'COLUMN'. If -cifti-roi
    is specified, no other -*-roi option may be specified. If not using
    -cifti-roi, any -*-roi options not present will discard the relevant
    structure, if present in the input file.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiRestrictDenseMapOutputs`).
    """
    cifti_restrict_dense_map_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_RESTRICT_DENSE_MAP_METADATA)
    params = execution.params(params)
    cargs = cifti_restrict_dense_map_cargs(params, execution)
    ret = cifti_restrict_dense_map_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_restrict_dense_map(
    cifti_in: InputPathType,
    direction: str,
    cifti_out: str,
    roi_vol: InputPathType | None = None,
    roi_metric: InputPathType | None = None,
    roi_metric_: InputPathType | None = None,
    roi_metric_2: InputPathType | None = None,
    roi_cifti: InputPathType | None = None,
    runner: Runner | None = None,
) -> CiftiRestrictDenseMapOutputs:
    """
    EXCLUDE BRAINORDINATES FROM A CIFTI FILE.
    
    Writes a modified version of <cifti-in>, where all brainordinates outside
    the specified roi(s) are removed from the file. The direction can be either
    an integer starting from 1, or the strings 'ROW' or 'COLUMN'. If -cifti-roi
    is specified, no other -*-roi option may be specified. If not using
    -cifti-roi, any -*-roi options not present will discard the relevant
    structure, if present in the input file.
    
    Args:
        cifti_in: the input cifti.
        direction: which dimension to change the mapping on (integer, 'ROW', or\
            'COLUMN').
        cifti_out: the output cifti.
        roi_vol: voxels to use\
            \
            the roi volume file.
        roi_metric: vertices to use from cerebellum\
            \
            the cerebellum roi as a metric file.
        roi_metric_: vertices to use from right hemisphere\
            \
            the right roi as a metric file.
        roi_metric_2: vertices to use from left hemisphere\
            \
            the left roi as a metric file.
        roi_cifti: cifti file containing combined rois\
            \
            the rois as a cifti file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiRestrictDenseMapOutputs`).
    """
    params = cifti_restrict_dense_map_params(
        cifti_in=cifti_in,
        direction=direction,
        cifti_out=cifti_out,
        roi_vol=roi_vol,
        roi_metric=roi_metric,
        roi_metric_=roi_metric_,
        roi_metric_2=roi_metric_2,
        roi_cifti=roi_cifti,
    )
    return cifti_restrict_dense_map_execute(params, runner)


__all__ = [
    "CIFTI_RESTRICT_DENSE_MAP_METADATA",
    "CiftiRestrictDenseMapOutputs",
    "CiftiRestrictDenseMapParamsDict",
    "CiftiRestrictDenseMapParamsDictTagged",
    "cifti_restrict_dense_map",
    "cifti_restrict_dense_map_execute",
    "cifti_restrict_dense_map_params",
]
