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

import typing
import pathlib
from styxdefs import *

CIFTI_CREATE_SCALAR_SERIES_METADATA = Metadata(
    id="8d713a958679f48506f74cec988ea68de2166f03.workbench",
    name="cifti-create-scalar-series",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiCreateScalarSeriesSeriesParamsDictNoTag = typing.TypedDict('_CiftiCreateScalarSeriesSeriesParamsDictNoTag', {
    "unit": str,
    "start": float,
    "step": float,
})
CiftiCreateScalarSeriesSeriesParamsDictTagged = typing.TypedDict('CiftiCreateScalarSeriesSeriesParamsDictTagged', {
    "@type": typing.Literal["series"],
    "unit": str,
    "start": float,
    "step": float,
})
CiftiCreateScalarSeriesSeriesParamsDict = _CiftiCreateScalarSeriesSeriesParamsDictNoTag | CiftiCreateScalarSeriesSeriesParamsDictTagged


_CiftiCreateScalarSeriesParamsDictNoTag = typing.TypedDict('_CiftiCreateScalarSeriesParamsDictNoTag', {
    "input": str,
    "cifti-out": str,
    "series": typing.NotRequired[CiftiCreateScalarSeriesSeriesParamsDict | None],
    "file": typing.NotRequired[str | None],
    "transpose": bool,
})
CiftiCreateScalarSeriesParamsDictTagged = typing.TypedDict('CiftiCreateScalarSeriesParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-create-scalar-series"],
    "input": str,
    "cifti-out": str,
    "series": typing.NotRequired[CiftiCreateScalarSeriesSeriesParamsDict | None],
    "file": typing.NotRequired[str | None],
    "transpose": bool,
})
CiftiCreateScalarSeriesParamsDict = _CiftiCreateScalarSeriesParamsDictNoTag | CiftiCreateScalarSeriesParamsDictTagged


def cifti_create_scalar_series_series(
    unit: str,
    start: float,
    step: float,
) -> CiftiCreateScalarSeriesSeriesParamsDictTagged:
    """
    Build parameters.
    
    Args:
        unit: the unit to use.
        start: the value at the first series point.
        step: the interval between series points.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "series",
        "unit": unit,
        "start": start,
        "step": step,
    }
    return params


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


def cifti_create_scalar_series_series_cargs(
    params: CiftiCreateScalarSeriesSeriesParamsDict,
    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([
        "-series",
        params.get("unit", None),
        str(params.get("start", None)),
        str(params.get("step", None))
    ])
    return cargs


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


def cifti_create_scalar_series_params(
    input_: str,
    cifti_out: str,
    series: CiftiCreateScalarSeriesSeriesParamsDict | None = None,
    file: str | None = None,
    transpose: bool = False,
) -> CiftiCreateScalarSeriesParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_: input file.
        cifti_out: output cifti file.
        series: set the units and values of the series.
        file: use a text file to set names on scalar dimension\
            \
            text file containing names, one per line.
        transpose: use if the rows of the text file are along the scalar\
            dimension.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-create-scalar-series",
        "input": input_,
        "cifti-out": cifti_out,
        "transpose": transpose,
    }
    if series is not None:
        params["series"] = series
    if file is not None:
        params["file"] = file
    return params


def cifti_create_scalar_series_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiCreateScalarSeriesParamsDict` 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("input", None) is None:
        raise StyxValidationError("`input` must not be None")
    if not isinstance(params["input"], str):
        raise StyxValidationError(f'`input` has the wrong type: Received `{type(params.get("input", None))}` expected `str`')
    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("series", None) is not None:
        cifti_create_scalar_series_series_validate(params["series"])
    if params.get("file", None) is not None:
        if not isinstance(params["file"], str):
            raise StyxValidationError(f'`file` has the wrong type: Received `{type(params.get("file", None))}` expected `str | None`')
    if params.get("transpose", False) is None:
        raise StyxValidationError("`transpose` must not be None")
    if not isinstance(params["transpose"], bool):
        raise StyxValidationError(f'`transpose` has the wrong type: Received `{type(params.get("transpose", False))}` expected `bool`')


def cifti_create_scalar_series_cargs(
    params: CiftiCreateScalarSeriesParamsDict,
    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-create-scalar-series"
    ])
    cargs.append(params.get("input", None))
    cargs.append(params.get("cifti-out", None))
    if params.get("series", None) is not None:
        cargs.extend(cifti_create_scalar_series_series_cargs(params.get("series", None), execution))
    if params.get("file", None) is not None:
        cargs.extend([
            "-name-file",
            params.get("file", None)
        ])
    if params.get("transpose", False):
        cargs.append("-transpose")
    return cargs


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


def cifti_create_scalar_series_execute(
    params: CiftiCreateScalarSeriesParamsDict,
    runner: Runner | None = None,
) -> CiftiCreateScalarSeriesOutputs:
    """
    IMPORT SERIES DATA INTO CIFTI.
    
    Convert a text file containing series of equal length into a cifti file. The
    text file should have lines made up of numbers separated by whitespace, with
    no extra newlines between lines.
    
    The <unit> argument must be one of the following:
    
    SECOND
    HERTZ
    METER
    RADIAN.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiCreateScalarSeriesOutputs`).
    """
    cifti_create_scalar_series_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_CREATE_SCALAR_SERIES_METADATA)
    params = execution.params(params)
    cargs = cifti_create_scalar_series_cargs(params, execution)
    ret = cifti_create_scalar_series_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_create_scalar_series(
    input_: str,
    cifti_out: str,
    series: CiftiCreateScalarSeriesSeriesParamsDict | None = None,
    file: str | None = None,
    transpose: bool = False,
    runner: Runner | None = None,
) -> CiftiCreateScalarSeriesOutputs:
    """
    IMPORT SERIES DATA INTO CIFTI.
    
    Convert a text file containing series of equal length into a cifti file. The
    text file should have lines made up of numbers separated by whitespace, with
    no extra newlines between lines.
    
    The <unit> argument must be one of the following:
    
    SECOND
    HERTZ
    METER
    RADIAN.
    
    Args:
        input_: input file.
        cifti_out: output cifti file.
        series: set the units and values of the series.
        file: use a text file to set names on scalar dimension\
            \
            text file containing names, one per line.
        transpose: use if the rows of the text file are along the scalar\
            dimension.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiCreateScalarSeriesOutputs`).
    """
    params = cifti_create_scalar_series_params(
        input_=input_,
        cifti_out=cifti_out,
        series=series,
        file=file,
        transpose=transpose,
    )
    return cifti_create_scalar_series_execute(params, runner)


__all__ = [
    "CIFTI_CREATE_SCALAR_SERIES_METADATA",
    "CiftiCreateScalarSeriesOutputs",
    "CiftiCreateScalarSeriesParamsDict",
    "CiftiCreateScalarSeriesParamsDictTagged",
    "CiftiCreateScalarSeriesSeriesParamsDict",
    "CiftiCreateScalarSeriesSeriesParamsDictTagged",
    "cifti_create_scalar_series",
    "cifti_create_scalar_series_execute",
    "cifti_create_scalar_series_params",
    "cifti_create_scalar_series_series",
]
