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

import typing
import pathlib
from styxdefs import *

CIFTI_MERGE_METADATA = Metadata(
    id="a4ffb5e806ff58cf992a8408091b306432b7db9b.boutiques",
    name="cifti-merge",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiMergeUpToParameters = typing.TypedDict('CiftiMergeUpToParameters', {
    "@type": typing.NotRequired[typing.Literal["up_to"]],
    "last_index": str,
    "opt_reverse": bool,
})
CiftiMergeUpToParametersTagged = typing.TypedDict('CiftiMergeUpToParametersTagged', {
    "@type": typing.Literal["up_to"],
    "last_index": str,
    "opt_reverse": bool,
})


CiftiMergeIndexParameters = typing.TypedDict('CiftiMergeIndexParameters', {
    "@type": typing.NotRequired[typing.Literal["index"]],
    "index": str,
    "up_to": typing.NotRequired[CiftiMergeUpToParameters | None],
})
CiftiMergeIndexParametersTagged = typing.TypedDict('CiftiMergeIndexParametersTagged', {
    "@type": typing.Literal["index"],
    "index": str,
    "up_to": typing.NotRequired[CiftiMergeUpToParameters | None],
})


CiftiMergeCiftiParameters = typing.TypedDict('CiftiMergeCiftiParameters', {
    "@type": typing.NotRequired[typing.Literal["cifti"]],
    "cifti_in": InputPathType,
    "index": typing.NotRequired[list[CiftiMergeIndexParameters] | None],
})
CiftiMergeCiftiParametersTagged = typing.TypedDict('CiftiMergeCiftiParametersTagged', {
    "@type": typing.Literal["cifti"],
    "cifti_in": InputPathType,
    "index": typing.NotRequired[list[CiftiMergeIndexParameters] | None],
})


CiftiMergeParameters = typing.TypedDict('CiftiMergeParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-merge"]],
    "cifti_out": str,
    "opt_direction_direction": typing.NotRequired[str | None],
    "opt_mem_limit_limit_gb": typing.NotRequired[float | None],
    "cifti": typing.NotRequired[list[CiftiMergeCiftiParameters] | None],
})
CiftiMergeParametersTagged = typing.TypedDict('CiftiMergeParametersTagged', {
    "@type": typing.Literal["workbench/cifti-merge"],
    "cifti_out": str,
    "opt_direction_direction": typing.NotRequired[str | None],
    "opt_mem_limit_limit_gb": typing.NotRequired[float | None],
    "cifti": typing.NotRequired[list[CiftiMergeCiftiParameters] | None],
})


def cifti_merge_up_to_params(
    last_index: str,
    opt_reverse: bool = False,
) -> CiftiMergeUpToParametersTagged:
    """
    Build parameters.
    
    Args:
        last_index: the number or name of the last index to include.
        opt_reverse: use the range in reverse order.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "up_to",
        "last_index": last_index,
        "opt_reverse": opt_reverse,
    }
    return params


def cifti_merge_up_to_cargs(
    params: CiftiMergeUpToParameters,
    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.append("-up-to")
    cargs.append(params.get("last_index", None))
    if params.get("opt_reverse", False):
        cargs.append("-reverse")
    return cargs


def cifti_merge_index_params(
    index: str,
    up_to: CiftiMergeUpToParameters | None = None,
) -> CiftiMergeIndexParametersTagged:
    """
    Build parameters.
    
    Args:
        index: the index number (starting from 1), or name.
        up_to: use an inclusive range of indices.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "index",
        "index": index,
    }
    if up_to is not None:
        params["up_to"] = up_to
    return params


def cifti_merge_index_cargs(
    params: CiftiMergeIndexParameters,
    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.append("-index")
    cargs.append(params.get("index", None))
    if params.get("up_to", None) is not None:
        cargs.extend(cifti_merge_up_to_cargs(params.get("up_to", None), execution))
    return cargs


def cifti_merge_cifti_params(
    cifti_in: InputPathType,
    index: list[CiftiMergeIndexParameters] | None = None,
) -> CiftiMergeCiftiParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: a cifti file to use data from.
        index: select a single index to use.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "cifti",
        "cifti_in": cifti_in,
    }
    if index is not None:
        params["index"] = index
    return params


def cifti_merge_cifti_cargs(
    params: CiftiMergeCiftiParameters,
    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.append("-cifti")
    cargs.append(execution.input_file(params.get("cifti_in", None)))
    if params.get("index", None) is not None:
        cargs.extend([a for c in [cifti_merge_index_cargs(s, execution) for s in params.get("index", None)] for a in c])
    return cargs


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


def cifti_merge_params(
    cifti_out: str,
    opt_direction_direction: str | None = None,
    opt_mem_limit_limit_gb: float | None = None,
    cifti: list[CiftiMergeCiftiParameters] | None = None,
) -> CiftiMergeParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti_out: output cifti file.
        opt_direction_direction: merge in a direction other than along rows:\
            the dimension to split/concatenate along, default ROW.
        opt_mem_limit_limit_gb: restrict memory used for file reading\
            efficiency: memory limit in gigabytes.
        cifti: specify an input cifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-merge",
        "cifti_out": cifti_out,
    }
    if opt_direction_direction is not None:
        params["opt_direction_direction"] = opt_direction_direction
    if opt_mem_limit_limit_gb is not None:
        params["opt_mem_limit_limit_gb"] = opt_mem_limit_limit_gb
    if cifti is not None:
        params["cifti"] = cifti
    return params


def cifti_merge_cargs(
    params: CiftiMergeParameters,
    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.append("wb_command")
    cargs.append("-cifti-merge")
    cargs.append(params.get("cifti_out", None))
    if params.get("opt_direction_direction", None) is not None:
        cargs.extend([
            "-direction",
            params.get("opt_direction_direction", None)
        ])
    if params.get("opt_mem_limit_limit_gb", None) is not None:
        cargs.extend([
            "-mem-limit",
            str(params.get("opt_mem_limit_limit_gb", None))
        ])
    if params.get("cifti", None) is not None:
        cargs.extend([a for c in [cifti_merge_cifti_cargs(s, execution) for s in params.get("cifti", None)] for a in c])
    return cargs


def cifti_merge_outputs(
    params: CiftiMergeParameters,
    execution: Execution,
) -> CiftiMergeOutputs:
    """
    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 = CiftiMergeOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(params.get("cifti_out", None)),
    )
    return ret


def cifti_merge_execute(
    params: CiftiMergeParameters,
    runner: Runner | None = None,
) -> CiftiMergeOutputs:
    """
    cifti-merge
    
    Merge or split on series, scalar, or label dimensions.
    
    Given input CIFTI files for which mappings along the selected direction are
    the same type, all either series, scalars, or labels, and the other
    dimensions are index-compatible, this command concatenates the data in the
    specified indices/ranges along the selected direction (by default, on
    typical 2D cifti, concatenate horizontally, so rows become longer). The
    direction can be either an integer starting from 1, or the strings 'ROW' or
    'COLUMN'.
    
    Example: wb_command -cifti-merge out.dtseries.nii -cifti first.dtseries.nii
    -index 1 -cifti second.dtseries.nii
    
    This example would take the first column from first.dtseries.nii, followed
    by all columns from second.dtseries.nii, and write these columns to
    out.dtseries.nii. .
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiMergeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_MERGE_METADATA)
    params = execution.params(params)
    cargs = cifti_merge_cargs(params, execution)
    ret = cifti_merge_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_merge(
    cifti_out: str,
    opt_direction_direction: str | None = None,
    opt_mem_limit_limit_gb: float | None = None,
    cifti: list[CiftiMergeCiftiParameters] | None = None,
    runner: Runner | None = None,
) -> CiftiMergeOutputs:
    """
    cifti-merge
    
    Merge or split on series, scalar, or label dimensions.
    
    Given input CIFTI files for which mappings along the selected direction are
    the same type, all either series, scalars, or labels, and the other
    dimensions are index-compatible, this command concatenates the data in the
    specified indices/ranges along the selected direction (by default, on
    typical 2D cifti, concatenate horizontally, so rows become longer). The
    direction can be either an integer starting from 1, or the strings 'ROW' or
    'COLUMN'.
    
    Example: wb_command -cifti-merge out.dtseries.nii -cifti first.dtseries.nii
    -index 1 -cifti second.dtseries.nii
    
    This example would take the first column from first.dtseries.nii, followed
    by all columns from second.dtseries.nii, and write these columns to
    out.dtseries.nii. .
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        cifti_out: output cifti file.
        opt_direction_direction: merge in a direction other than along rows:\
            the dimension to split/concatenate along, default ROW.
        opt_mem_limit_limit_gb: restrict memory used for file reading\
            efficiency: memory limit in gigabytes.
        cifti: specify an input cifti file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiMergeOutputs`).
    """
    params = cifti_merge_params(
        cifti_out=cifti_out,
        opt_direction_direction=opt_direction_direction,
        opt_mem_limit_limit_gb=opt_mem_limit_limit_gb,
        cifti=cifti,
    )
    return cifti_merge_execute(params, runner)


__all__ = [
    "CIFTI_MERGE_METADATA",
    "CiftiMergeOutputs",
    "cifti_merge",
    "cifti_merge_cifti_params",
    "cifti_merge_execute",
    "cifti_merge_index_params",
    "cifti_merge_params",
    "cifti_merge_up_to_params",
]
