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

import typing
import pathlib
from styxdefs import *
import dataclasses

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


@dataclasses.dataclass
class CiftiMergeUpTo:
    """
    use an inclusive range of indices.
    """
    last_index: str
    """the number or name of the last index to include"""
    opt_reverse: bool = False
    """use the range in reverse order"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-up-to")
        cargs.append(self.last_index)
        if self.opt_reverse:
            cargs.append("-reverse")
        return cargs


@dataclasses.dataclass
class CiftiMergeIndex:
    """
    select a single index to use.
    """
    index: str
    """the index number (starting from 1), or name"""
    up_to: CiftiMergeUpTo | None = None
    """use an inclusive range of indices"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-index")
        cargs.append(self.index)
        if self.up_to is not None:
            cargs.extend(self.up_to.run(execution))
        return cargs


@dataclasses.dataclass
class CiftiMergeCifti:
    """
    specify an input cifti file.
    """
    cifti_in: InputPathType
    """a cifti file to use data from"""
    index: list[CiftiMergeIndex] | None = None
    """select a single index to use"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-cifti")
        cargs.append(execution.input_file(self.cifti_in))
        if self.index is not None:
            cargs.extend([a for c in [s.run(execution) for s in self.index] for a in c])
        return cargs


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


def cifti_merge(
    cifti_out: str,
    opt_direction_direction: str | None = None,
    opt_mem_limit_limit_gb: float | None = None,
    cifti: list[CiftiMergeCifti] | None = None,
    runner: Runner | None = None,
) -> CiftiMergeOutputs:
    """
    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`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_MERGE_METADATA)
    cargs = []
    cargs.append("wb_command")
    cargs.append("-cifti-merge")
    cargs.append(cifti_out)
    if opt_direction_direction is not None:
        cargs.extend([
            "-direction",
            opt_direction_direction
        ])
    if opt_mem_limit_limit_gb is not None:
        cargs.extend([
            "-mem-limit",
            str(opt_mem_limit_limit_gb)
        ])
    if cifti is not None:
        cargs.extend([a for c in [s.run(execution) for s in cifti] for a in c])
    ret = CiftiMergeOutputs(
        root=execution.output_file("."),
        cifti_out=execution.output_file(cifti_out),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "CIFTI_MERGE_METADATA",
    "CiftiMergeCifti",
    "CiftiMergeIndex",
    "CiftiMergeOutputs",
    "CiftiMergeUpTo",
    "cifti_merge",
]
