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

import typing
import pathlib
from styxdefs import *

CIFTI_MERGE_PARCELS_METADATA = Metadata(
    id="6843c1951c4ae4950f7c0694f8574395469f0819.boutiques",
    name="cifti-merge-parcels",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiMergeParcelsCiftiParameters = typing.TypedDict('CiftiMergeParcelsCiftiParameters', {
    "@type": typing.NotRequired[typing.Literal["cifti"]],
    "cifti_in": InputPathType,
})
CiftiMergeParcelsCiftiParametersTagged = typing.TypedDict('CiftiMergeParcelsCiftiParametersTagged', {
    "@type": typing.Literal["cifti"],
    "cifti_in": InputPathType,
})


CiftiMergeParcelsParameters = typing.TypedDict('CiftiMergeParcelsParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-merge-parcels"]],
    "direction": str,
    "cifti_out": str,
    "cifti": typing.NotRequired[list[CiftiMergeParcelsCiftiParameters] | None],
})
CiftiMergeParcelsParametersTagged = typing.TypedDict('CiftiMergeParcelsParametersTagged', {
    "@type": typing.Literal["workbench/cifti-merge-parcels"],
    "direction": str,
    "cifti_out": str,
    "cifti": typing.NotRequired[list[CiftiMergeParcelsCiftiParameters] | None],
})


def cifti_merge_parcels_cifti_params(
    cifti_in: InputPathType,
) -> CiftiMergeParcelsCiftiParametersTagged:
    """
    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_parcels_cifti_cargs(
    params: CiftiMergeParcelsCiftiParameters,
    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)))
    return cargs


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


def cifti_merge_parcels_params(
    direction: str,
    cifti_out: str,
    cifti: list[CiftiMergeParcelsCiftiParameters] | None = None,
) -> CiftiMergeParcelsParametersTagged:
    """
    Build parameters.
    
    Args:
        direction: which dimension to merge along (integer, 'ROW', or 'COLUMN').
        cifti_out: the output cifti file.
        cifti: specify an input cifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-merge-parcels",
        "direction": direction,
        "cifti_out": cifti_out,
    }
    if cifti is not None:
        params["cifti"] = cifti
    return params


def cifti_merge_parcels_cargs(
    params: CiftiMergeParcelsParameters,
    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-parcels")
    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_parcels_cifti_cargs(s, execution) for s in params.get("cifti", None)] for a in c])
    return cargs


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


def cifti_merge_parcels_execute(
    params: CiftiMergeParcelsParameters,
    runner: Runner | None = None,
) -> CiftiMergeParcelsOutputs:
    """
    cifti-merge-parcels
    
    Merge cifti files along parcels dimension.
    
    The input cifti files must have matching mappings along the direction not
    specified, and the mapping along the specified direction must be parcels.
    The direction can be either an integer starting from 1, or the strings 'ROW'
    or 'COLUMN'.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiMergeParcelsOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_MERGE_PARCELS_METADATA)
    params = execution.params(params)
    cargs = cifti_merge_parcels_cargs(params, execution)
    ret = cifti_merge_parcels_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_merge_parcels(
    direction: str,
    cifti_out: str,
    cifti: list[CiftiMergeParcelsCiftiParameters] | None = None,
    runner: Runner | None = None,
) -> CiftiMergeParcelsOutputs:
    """
    cifti-merge-parcels
    
    Merge cifti files along parcels dimension.
    
    The input cifti files must have matching mappings along the direction not
    specified, and the mapping along the specified direction must be parcels.
    The direction can be either an integer starting from 1, or the strings 'ROW'
    or 'COLUMN'.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        direction: which dimension to merge along (integer, 'ROW', or 'COLUMN').
        cifti_out: the output cifti file.
        cifti: specify an input cifti file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiMergeParcelsOutputs`).
    """
    params = cifti_merge_parcels_params(
        direction=direction,
        cifti_out=cifti_out,
        cifti=cifti,
    )
    return cifti_merge_parcels_execute(params, runner)


__all__ = [
    "CIFTI_MERGE_PARCELS_METADATA",
    "CiftiMergeParcelsOutputs",
    "cifti_merge_parcels",
    "cifti_merge_parcels_cifti_params",
    "cifti_merge_parcels_execute",
    "cifti_merge_parcels_params",
]
