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

import typing
import pathlib
from styxdefs import *

CIFTI_MERGE_DENSE_METADATA = Metadata(
    id="31ef2d25051e5edb39a80b7e1a1896b565b06aea.workbench",
    name="cifti-merge-dense",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiMergeDenseCiftiParamsDictNoTag = typing.TypedDict('_CiftiMergeDenseCiftiParamsDictNoTag', {
    "cifti-in": InputPathType,
})
CiftiMergeDenseCiftiParamsDictTagged = typing.TypedDict('CiftiMergeDenseCiftiParamsDictTagged', {
    "@type": typing.Literal["cifti"],
    "cifti-in": InputPathType,
})
CiftiMergeDenseCiftiParamsDict = _CiftiMergeDenseCiftiParamsDictNoTag | CiftiMergeDenseCiftiParamsDictTagged


_CiftiMergeDenseParamsDictNoTag = typing.TypedDict('_CiftiMergeDenseParamsDictNoTag', {
    "direction": str,
    "cifti-out": str,
    "cifti": typing.NotRequired[list[CiftiMergeDenseCiftiParamsDict] | None],
    "action": typing.NotRequired[str | None],
})
CiftiMergeDenseParamsDictTagged = typing.TypedDict('CiftiMergeDenseParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-merge-dense"],
    "direction": str,
    "cifti-out": str,
    "cifti": typing.NotRequired[list[CiftiMergeDenseCiftiParamsDict] | None],
    "action": typing.NotRequired[str | None],
})
CiftiMergeDenseParamsDict = _CiftiMergeDenseParamsDictNoTag | CiftiMergeDenseParamsDictTagged


def cifti_merge_dense_cifti(
    cifti_in: InputPathType,
) -> CiftiMergeDenseCiftiParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: a cifti file to merge.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "cifti",
        "cifti-in": cifti_in,
    }
    return params


def cifti_merge_dense_cifti_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiMergeDenseCiftiParamsDict` 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`')


def cifti_merge_dense_cifti_cargs(
    params: CiftiMergeDenseCiftiParamsDict,
    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([
        "-cifti",
        execution.input_file(params.get("cifti-in", None))
    ])
    return cargs


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


def cifti_merge_dense_params(
    direction: str,
    cifti_out: str,
    cifti: list[CiftiMergeDenseCiftiParamsDict] | None = None,
    action: str | None = None,
) -> CiftiMergeDenseParamsDictTagged:
    """
    Build parameters.
    
    Args:
        direction: which dimension to merge along, ROW or COLUMN.
        cifti_out: the output cifti file.
        cifti: specify an input cifti file.
        action: how to handle conflicts between label keys\
            \
            'ERROR', 'FIRST', or 'LEGACY', default 'ERROR', use 'LEGACY' to\
            match v1.4.2 and earlier.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-merge-dense",
        "direction": direction,
        "cifti-out": cifti_out,
    }
    if cifti is not None:
        params["cifti"] = cifti
    if action is not None:
        params["action"] = action
    return params


def cifti_merge_dense_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiMergeDenseParamsDict` 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("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("cifti", None) is not None:
        if not isinstance(params["cifti"], list):
            raise StyxValidationError(f'`cifti` has the wrong type: Received `{type(params.get("cifti", None))}` expected `list[CiftiMergeDenseCiftiParamsDict] | None`')
        for e in params["cifti"]:
            cifti_merge_dense_cifti_validate(e)
    if params.get("action", None) is not None:
        if not isinstance(params["action"], str):
            raise StyxValidationError(f'`action` has the wrong type: Received `{type(params.get("action", None))}` expected `str | None`')


def cifti_merge_dense_cargs(
    params: CiftiMergeDenseParamsDict,
    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-merge-dense"
    ])
    cargs.append(params.get("direction", None))
    cargs.append(params.get("cifti-out", None))
    if params.get("cifti", None) is not None:
        cargs.extend([a for c in [cifti_merge_dense_cifti_cargs(s, execution) for s in params.get("cifti", None)] for a in c])
    if params.get("action", None) is not None:
        cargs.extend([
            "-label-collision",
            params.get("action", None)
        ])
    return cargs


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


def cifti_merge_dense_execute(
    params: CiftiMergeDenseParamsDict,
    runner: Runner | None = None,
) -> CiftiMergeDenseOutputs:
    """
    MERGE CIFTI FILES ALONG DENSE DIMENSION.
    
    The input cifti files must have matching mappings along the direction not
    specified, and the mapping along the specified direction must be brain
    models.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiMergeDenseOutputs`).
    """
    cifti_merge_dense_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_MERGE_DENSE_METADATA)
    params = execution.params(params)
    cargs = cifti_merge_dense_cargs(params, execution)
    ret = cifti_merge_dense_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_merge_dense(
    direction: str,
    cifti_out: str,
    cifti: list[CiftiMergeDenseCiftiParamsDict] | None = None,
    action: str | None = None,
    runner: Runner | None = None,
) -> CiftiMergeDenseOutputs:
    """
    MERGE CIFTI FILES ALONG DENSE DIMENSION.
    
    The input cifti files must have matching mappings along the direction not
    specified, and the mapping along the specified direction must be brain
    models.
    
    Args:
        direction: which dimension to merge along, ROW or COLUMN.
        cifti_out: the output cifti file.
        cifti: specify an input cifti file.
        action: how to handle conflicts between label keys\
            \
            'ERROR', 'FIRST', or 'LEGACY', default 'ERROR', use 'LEGACY' to\
            match v1.4.2 and earlier.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiMergeDenseOutputs`).
    """
    params = cifti_merge_dense_params(
        direction=direction,
        cifti_out=cifti_out,
        cifti=cifti,
        action=action,
    )
    return cifti_merge_dense_execute(params, runner)


__all__ = [
    "CIFTI_MERGE_DENSE_METADATA",
    "CiftiMergeDenseCiftiParamsDict",
    "CiftiMergeDenseCiftiParamsDictTagged",
    "CiftiMergeDenseOutputs",
    "CiftiMergeDenseParamsDict",
    "CiftiMergeDenseParamsDictTagged",
    "cifti_merge_dense",
    "cifti_merge_dense_cifti",
    "cifti_merge_dense_execute",
    "cifti_merge_dense_params",
]
