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

import typing
import pathlib
from styxdefs import *

CIFTI_TRANSPOSE_METADATA = Metadata(
    id="a38fc279857d9723961ff9db61fed1fba00e53c2.workbench",
    name="cifti-transpose",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiTransposeParamsDictNoTag = typing.TypedDict('_CiftiTransposeParamsDictNoTag', {
    "cifti-in": InputPathType,
    "cifti-out": str,
    "limit-GB": typing.NotRequired[float | None],
})
CiftiTransposeParamsDictTagged = typing.TypedDict('CiftiTransposeParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-transpose"],
    "cifti-in": InputPathType,
    "cifti-out": str,
    "limit-GB": typing.NotRequired[float | None],
})
CiftiTransposeParamsDict = _CiftiTransposeParamsDictNoTag | CiftiTransposeParamsDictTagged


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


def cifti_transpose_params(
    cifti_in: InputPathType,
    cifti_out: str,
    limit_gb: float | None = None,
) -> CiftiTransposeParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: the input cifti file.
        cifti_out: the output cifti file.
        limit_gb: restrict memory usage\
            \
            memory limit in gigabytes.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-transpose",
        "cifti-in": cifti_in,
        "cifti-out": cifti_out,
    }
    if limit_gb is not None:
        params["limit-GB"] = limit_gb
    return params


def cifti_transpose_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiTransposeParamsDict` 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`')
    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("limit-GB", None) is not None:
        if not isinstance(params["limit-GB"], (float, int)):
            raise StyxValidationError(f'`limit-GB` has the wrong type: Received `{type(params.get("limit-GB", None))}` expected `float | None`')


def cifti_transpose_cargs(
    params: CiftiTransposeParamsDict,
    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-transpose"
    ])
    cargs.append(execution.input_file(params.get("cifti-in", None)))
    cargs.append(params.get("cifti-out", None))
    if params.get("limit-GB", None) is not None:
        cargs.extend([
            "-mem-limit",
            str(params.get("limit-GB", None))
        ])
    return cargs


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


def cifti_transpose_execute(
    params: CiftiTransposeParamsDict,
    runner: Runner | None = None,
) -> CiftiTransposeOutputs:
    """
    TRANSPOSE A CIFTI FILE.
    
    The input must be a 2-dimensional cifti file. The output is a cifti file
    where every row in the input is a column in the output.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiTransposeOutputs`).
    """
    cifti_transpose_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_TRANSPOSE_METADATA)
    params = execution.params(params)
    cargs = cifti_transpose_cargs(params, execution)
    ret = cifti_transpose_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_transpose(
    cifti_in: InputPathType,
    cifti_out: str,
    limit_gb: float | None = None,
    runner: Runner | None = None,
) -> CiftiTransposeOutputs:
    """
    TRANSPOSE A CIFTI FILE.
    
    The input must be a 2-dimensional cifti file. The output is a cifti file
    where every row in the input is a column in the output.
    
    Args:
        cifti_in: the input cifti file.
        cifti_out: the output cifti file.
        limit_gb: restrict memory usage\
            \
            memory limit in gigabytes.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiTransposeOutputs`).
    """
    params = cifti_transpose_params(
        cifti_in=cifti_in,
        cifti_out=cifti_out,
        limit_gb=limit_gb,
    )
    return cifti_transpose_execute(params, runner)


__all__ = [
    "CIFTI_TRANSPOSE_METADATA",
    "CiftiTransposeOutputs",
    "CiftiTransposeParamsDict",
    "CiftiTransposeParamsDictTagged",
    "cifti_transpose",
    "cifti_transpose_execute",
    "cifti_transpose_params",
]
