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

import typing
import pathlib
from styxdefs import *

BACKEND_AVERAGE_DENSE_ROI_METADATA = Metadata(
    id="af0de4e5ef947f744f8051acd2cc8811f3f4cf73.workbench",
    name="backend-average-dense-roi",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_BackendAverageDenseRoiParamsDictNoTag = typing.TypedDict('_BackendAverageDenseRoiParamsDictNoTag', {
    "index-list": str,
    "out-file": str,
})
BackendAverageDenseRoiParamsDictTagged = typing.TypedDict('BackendAverageDenseRoiParamsDictTagged', {
    "@type": typing.Literal["workbench/backend-average-dense-roi"],
    "index-list": str,
    "out-file": str,
})
BackendAverageDenseRoiParamsDict = _BackendAverageDenseRoiParamsDictNoTag | BackendAverageDenseRoiParamsDictTagged


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


def backend_average_dense_roi_params(
    index_list: str,
    out_file: str,
) -> BackendAverageDenseRoiParamsDictTagged:
    """
    Build parameters.
    
    Args:
        index_list: comma separated list of cifti indexes to average.
        out_file: file to write the average row to.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/backend-average-dense-roi",
        "index-list": index_list,
        "out-file": out_file,
    }
    return params


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


def backend_average_dense_roi_cargs(
    params: BackendAverageDenseRoiParamsDict,
    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",
        "-backend-average-dense-roi"
    ])
    cargs.append(params.get("index-list", None))
    cargs.append(params.get("out-file", None))
    return cargs


def backend_average_dense_roi_outputs(
    params: BackendAverageDenseRoiParamsDict,
    execution: Execution,
) -> BackendAverageDenseRoiOutputs:
    """
    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 = BackendAverageDenseRoiOutputs(
        root=execution.output_file("."),
    )
    return ret


def backend_average_dense_roi_execute(
    params: BackendAverageDenseRoiParamsDict,
    runner: Runner | None = None,
) -> BackendAverageDenseRoiOutputs:
    """
    CONNECTOME DB BACKEND COMMAND FOR CIFTI AVERAGE DENSE ROI.
    
    This command is probably not the one you are looking for, try
    -cifti-average-dense-roi. It takes the list of cifti files to average from
    standard input, and writes its output as little endian, 32-bit integer of
    row size followed by the row as 32-bit floats.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BackendAverageDenseRoiOutputs`).
    """
    backend_average_dense_roi_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(BACKEND_AVERAGE_DENSE_ROI_METADATA)
    params = execution.params(params)
    cargs = backend_average_dense_roi_cargs(params, execution)
    ret = backend_average_dense_roi_outputs(params, execution)
    execution.run(cargs)
    return ret


def backend_average_dense_roi(
    index_list: str,
    out_file: str,
    runner: Runner | None = None,
) -> BackendAverageDenseRoiOutputs:
    """
    CONNECTOME DB BACKEND COMMAND FOR CIFTI AVERAGE DENSE ROI.
    
    This command is probably not the one you are looking for, try
    -cifti-average-dense-roi. It takes the list of cifti files to average from
    standard input, and writes its output as little endian, 32-bit integer of
    row size followed by the row as 32-bit floats.
    
    Args:
        index_list: comma separated list of cifti indexes to average.
        out_file: file to write the average row to.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BackendAverageDenseRoiOutputs`).
    """
    params = backend_average_dense_roi_params(
        index_list=index_list,
        out_file=out_file,
    )
    return backend_average_dense_roi_execute(params, runner)


__all__ = [
    "BACKEND_AVERAGE_DENSE_ROI_METADATA",
    "BackendAverageDenseRoiOutputs",
    "BackendAverageDenseRoiParamsDict",
    "BackendAverageDenseRoiParamsDictTagged",
    "backend_average_dense_roi",
    "backend_average_dense_roi_execute",
    "backend_average_dense_roi_params",
]
