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

import typing
import pathlib
from styxdefs import *

CIFTI_REORDER_METADATA = Metadata(
    id="0ad5648e651c6301fc696a16b14ed6ef9efc41a4.boutiques",
    name="cifti-reorder",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiReorderParameters = typing.TypedDict('CiftiReorderParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-reorder"]],
    "cifti_in": InputPathType,
    "direction": str,
    "reorder_list": str,
    "cifti_out": str,
})
CiftiReorderParametersTagged = typing.TypedDict('CiftiReorderParametersTagged', {
    "@type": typing.Literal["workbench/cifti-reorder"],
    "cifti_in": InputPathType,
    "direction": str,
    "reorder_list": str,
    "cifti_out": str,
})


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


def cifti_reorder_params(
    cifti_in: InputPathType,
    direction: str,
    reorder_list: str,
    cifti_out: str,
) -> CiftiReorderParametersTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: input cifti file.
        direction: which dimension to reorder along, ROW or COLUMN.
        reorder_list: a text file containing the desired order transformation.
        cifti_out: the reordered cifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-reorder",
        "cifti_in": cifti_in,
        "direction": direction,
        "reorder_list": reorder_list,
        "cifti_out": cifti_out,
    }
    return params


def cifti_reorder_cargs(
    params: CiftiReorderParameters,
    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-reorder")
    cargs.append(execution.input_file(params.get("cifti_in", None)))
    cargs.append(params.get("direction", None))
    cargs.append(params.get("reorder_list", None))
    cargs.append(params.get("cifti_out", None))
    return cargs


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


def cifti_reorder_execute(
    params: CiftiReorderParameters,
    runner: Runner | None = None,
) -> CiftiReorderOutputs:
    """
    cifti-reorder
    
    Reorder the parcels or scalar/label maps in a cifti file.
    
    The mapping along the specified direction must be parcels, scalars, or
    labels. For pscalar or ptseries, use COLUMN to reorder the parcels. For
    dlabel, use ROW. The <reorder-list> file must contain 1-based indices
    separated by whitespace (spaces, newlines, tabs, etc), with as many indices
    as <cifti-in> has along the specified dimension. These indices specify which
    current index should end up in that position, for instance, if the current
    order is 'A B C D', and the desired order is 'D A B C', the text file should
    contain '4 1 2 3'.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiReorderOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_REORDER_METADATA)
    params = execution.params(params)
    cargs = cifti_reorder_cargs(params, execution)
    ret = cifti_reorder_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_reorder(
    cifti_in: InputPathType,
    direction: str,
    reorder_list: str,
    cifti_out: str,
    runner: Runner | None = None,
) -> CiftiReorderOutputs:
    """
    cifti-reorder
    
    Reorder the parcels or scalar/label maps in a cifti file.
    
    The mapping along the specified direction must be parcels, scalars, or
    labels. For pscalar or ptseries, use COLUMN to reorder the parcels. For
    dlabel, use ROW. The <reorder-list> file must contain 1-based indices
    separated by whitespace (spaces, newlines, tabs, etc), with as many indices
    as <cifti-in> has along the specified dimension. These indices specify which
    current index should end up in that position, for instance, if the current
    order is 'A B C D', and the desired order is 'D A B C', the text file should
    contain '4 1 2 3'.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        cifti_in: input cifti file.
        direction: which dimension to reorder along, ROW or COLUMN.
        reorder_list: a text file containing the desired order transformation.
        cifti_out: the reordered cifti file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiReorderOutputs`).
    """
    params = cifti_reorder_params(
        cifti_in=cifti_in,
        direction=direction,
        reorder_list=reorder_list,
        cifti_out=cifti_out,
    )
    return cifti_reorder_execute(params, runner)


__all__ = [
    "CIFTI_REORDER_METADATA",
    "CiftiReorderOutputs",
    "cifti_reorder",
    "cifti_reorder_execute",
    "cifti_reorder_params",
]
