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

import typing
import pathlib
from styxdefs import *

CIFTI_CHANGE_MAPPING_METADATA = Metadata(
    id="98052ea0462fd3e196a00f6d6e0bcbac9ddc17e4.workbench",
    name="cifti-change-mapping",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiChangeMappingSeriesParamsDictNoTag = typing.TypedDict('_CiftiChangeMappingSeriesParamsDictNoTag', {
    "step": float,
    "start": float,
    "unit": typing.NotRequired[str | None],
})
CiftiChangeMappingSeriesParamsDictTagged = typing.TypedDict('CiftiChangeMappingSeriesParamsDictTagged', {
    "@type": typing.Literal["series"],
    "step": float,
    "start": float,
    "unit": typing.NotRequired[str | None],
})
CiftiChangeMappingSeriesParamsDict = _CiftiChangeMappingSeriesParamsDictNoTag | CiftiChangeMappingSeriesParamsDictTagged


_CiftiChangeMappingScalarParamsDictNoTag = typing.TypedDict('_CiftiChangeMappingScalarParamsDictNoTag', {
    "file": typing.NotRequired[str | None],
})
CiftiChangeMappingScalarParamsDictTagged = typing.TypedDict('CiftiChangeMappingScalarParamsDictTagged', {
    "@type": typing.Literal["scalar"],
    "file": typing.NotRequired[str | None],
})
CiftiChangeMappingScalarParamsDict = _CiftiChangeMappingScalarParamsDictNoTag | CiftiChangeMappingScalarParamsDictTagged


_CiftiChangeMappingFromCiftiParamsDictNoTag = typing.TypedDict('_CiftiChangeMappingFromCiftiParamsDictNoTag', {
    "template-cifti": InputPathType,
    "direction": str,
})
CiftiChangeMappingFromCiftiParamsDictTagged = typing.TypedDict('CiftiChangeMappingFromCiftiParamsDictTagged', {
    "@type": typing.Literal["from-cifti"],
    "template-cifti": InputPathType,
    "direction": str,
})
CiftiChangeMappingFromCiftiParamsDict = _CiftiChangeMappingFromCiftiParamsDictNoTag | CiftiChangeMappingFromCiftiParamsDictTagged


_CiftiChangeMappingParamsDictNoTag = typing.TypedDict('_CiftiChangeMappingParamsDictNoTag', {
    "data-cifti": InputPathType,
    "direction": str,
    "cifti-out": str,
    "series": typing.NotRequired[CiftiChangeMappingSeriesParamsDict | None],
    "scalar": typing.NotRequired[CiftiChangeMappingScalarParamsDict | None],
    "from-cifti": typing.NotRequired[CiftiChangeMappingFromCiftiParamsDict | None],
})
CiftiChangeMappingParamsDictTagged = typing.TypedDict('CiftiChangeMappingParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-change-mapping"],
    "data-cifti": InputPathType,
    "direction": str,
    "cifti-out": str,
    "series": typing.NotRequired[CiftiChangeMappingSeriesParamsDict | None],
    "scalar": typing.NotRequired[CiftiChangeMappingScalarParamsDict | None],
    "from-cifti": typing.NotRequired[CiftiChangeMappingFromCiftiParamsDict | None],
})
CiftiChangeMappingParamsDict = _CiftiChangeMappingParamsDictNoTag | CiftiChangeMappingParamsDictTagged


def cifti_change_mapping_series(
    step: float,
    start: float,
    unit: str | None = None,
) -> CiftiChangeMappingSeriesParamsDictTagged:
    """
    Build parameters.
    
    Args:
        step: increment between series points.
        start: start value of the series.
        unit: select unit for series (default SECOND)\
            \
            unit identifier.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "series",
        "step": step,
        "start": start,
    }
    if unit is not None:
        params["unit"] = unit
    return params


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


def cifti_change_mapping_series_cargs(
    params: CiftiChangeMappingSeriesParamsDict,
    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",
        str(params.get("step", None)),
        str(params.get("start", None))
    ])
    if params.get("unit", None) is not None:
        cargs.extend([
            "-unit",
            params.get("unit", None)
        ])
    return cargs


def cifti_change_mapping_scalar(
    file: str | None = None,
) -> CiftiChangeMappingScalarParamsDictTagged:
    """
    Build parameters.
    
    Args:
        file: specify names for the maps\
            \
            text file containing map names, one per line.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "scalar",
    }
    if file is not None:
        params["file"] = file
    return params


def cifti_change_mapping_scalar_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiChangeMappingScalarParamsDict` 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("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`')


def cifti_change_mapping_scalar_cargs(
    params: CiftiChangeMappingScalarParamsDict,
    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("-scalar")
    if params.get("file", None) is not None:
        cargs.extend([
            "-name-file",
            params.get("file", None)
        ])
    return cargs


def cifti_change_mapping_from_cifti(
    template_cifti: InputPathType,
    direction: str,
) -> CiftiChangeMappingFromCiftiParamsDictTagged:
    """
    Build parameters.
    
    Args:
        template_cifti: a cifti file containing the desired mapping.
        direction: which direction to copy the mapping from.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "from-cifti",
        "template-cifti": template_cifti,
        "direction": direction,
    }
    return params


def cifti_change_mapping_from_cifti_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiChangeMappingFromCiftiParamsDict` 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("template-cifti", None) is None:
        raise StyxValidationError("`template-cifti` must not be None")
    if not isinstance(params["template-cifti"], (pathlib.Path, str)):
        raise StyxValidationError(f'`template-cifti` has the wrong type: Received `{type(params.get("template-cifti", None))}` expected `InputPathType`')
    if params.get("direction", None) is None:
        raise StyxValidationError("`direction` must not be None")
    if not isinstance(params["direction"], str):
        raise StyxValidationError(f'`direction` has the wrong type: Received `{type(params.get("direction", None))}` expected `str`')


def cifti_change_mapping_from_cifti_cargs(
    params: CiftiChangeMappingFromCiftiParamsDict,
    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([
        "-from-cifti",
        execution.input_file(params.get("template-cifti", None)),
        params.get("direction", None)
    ])
    return cargs


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


def cifti_change_mapping_params(
    data_cifti: InputPathType,
    direction: str,
    cifti_out: str,
    series: CiftiChangeMappingSeriesParamsDict | None = None,
    scalar: CiftiChangeMappingScalarParamsDict | None = None,
    from_cifti: CiftiChangeMappingFromCiftiParamsDict | None = None,
) -> CiftiChangeMappingParamsDictTagged:
    """
    Build parameters.
    
    Args:
        data_cifti: the cifti file to use the data from.
        direction: which direction on <data-cifti> to replace the mapping.
        cifti_out: the output cifti file.
        series: set the mapping to series.
        scalar: set the mapping to scalar.
        from_cifti: copy mapping from another cifti file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-change-mapping",
        "data-cifti": data_cifti,
        "direction": direction,
        "cifti-out": cifti_out,
    }
    if series is not None:
        params["series"] = series
    if scalar is not None:
        params["scalar"] = scalar
    if from_cifti is not None:
        params["from-cifti"] = from_cifti
    return params


def cifti_change_mapping_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiChangeMappingParamsDict` 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("data-cifti", None) is None:
        raise StyxValidationError("`data-cifti` must not be None")
    if not isinstance(params["data-cifti"], (pathlib.Path, str)):
        raise StyxValidationError(f'`data-cifti` has the wrong type: Received `{type(params.get("data-cifti", None))}` expected `InputPathType`')
    if params.get("direction", None) is None:
        raise StyxValidationError("`direction` must not be None")
    if not isinstance(params["direction"], str):
        raise StyxValidationError(f'`direction` has the wrong type: Received `{type(params.get("direction", 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_change_mapping_series_validate(params["series"])
    if params.get("scalar", None) is not None:
        cifti_change_mapping_scalar_validate(params["scalar"])
    if params.get("from-cifti", None) is not None:
        cifti_change_mapping_from_cifti_validate(params["from-cifti"])


def cifti_change_mapping_cargs(
    params: CiftiChangeMappingParamsDict,
    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-change-mapping"
    ])
    cargs.append(execution.input_file(params.get("data-cifti", None)))
    cargs.append(params.get("direction", None))
    cargs.append(params.get("cifti-out", None))
    if params.get("series", None) is not None or params.get("scalar", None) is not None or params.get("from-cifti", None) is not None:
        cargs.extend([
            *(cifti_change_mapping_series_cargs(params.get("series", None), execution) if (params.get("series", None) is not None) else []),
            *(cifti_change_mapping_scalar_cargs(params.get("scalar", None), execution) if (params.get("scalar", None) is not None) else []),
            *(cifti_change_mapping_from_cifti_cargs(params.get("from-cifti", None), execution) if (params.get("from-cifti", None) is not None) else [])
        ])
    return cargs


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


def cifti_change_mapping_execute(
    params: CiftiChangeMappingParamsDict,
    runner: Runner | None = None,
) -> CiftiChangeMappingOutputs:
    """
    CONVERT TO SCALAR, COPY MAPPING, ETC.
    
    Take an existing cifti file and change one of the mappings. Exactly one of
    -series, -scalar, or -from-cifti must be specified. The direction can be
    either an integer starting from 1, or the strings 'ROW' or 'COLUMN'.
    
    The argument to -unit must be one of the following:
    
    SECOND
    HERTZ
    METER
    RADIAN.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiChangeMappingOutputs`).
    """
    cifti_change_mapping_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_CHANGE_MAPPING_METADATA)
    params = execution.params(params)
    cargs = cifti_change_mapping_cargs(params, execution)
    ret = cifti_change_mapping_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_change_mapping(
    data_cifti: InputPathType,
    direction: str,
    cifti_out: str,
    series: CiftiChangeMappingSeriesParamsDict | None = None,
    scalar: CiftiChangeMappingScalarParamsDict | None = None,
    from_cifti: CiftiChangeMappingFromCiftiParamsDict | None = None,
    runner: Runner | None = None,
) -> CiftiChangeMappingOutputs:
    """
    CONVERT TO SCALAR, COPY MAPPING, ETC.
    
    Take an existing cifti file and change one of the mappings. Exactly one of
    -series, -scalar, or -from-cifti must be specified. The direction can be
    either an integer starting from 1, or the strings 'ROW' or 'COLUMN'.
    
    The argument to -unit must be one of the following:
    
    SECOND
    HERTZ
    METER
    RADIAN.
    
    Args:
        data_cifti: the cifti file to use the data from.
        direction: which direction on <data-cifti> to replace the mapping.
        cifti_out: the output cifti file.
        series: set the mapping to series.
        scalar: set the mapping to scalar.
        from_cifti: copy mapping from another cifti file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiChangeMappingOutputs`).
    """
    params = cifti_change_mapping_params(
        data_cifti=data_cifti,
        direction=direction,
        cifti_out=cifti_out,
        series=series,
        scalar=scalar,
        from_cifti=from_cifti,
    )
    return cifti_change_mapping_execute(params, runner)


__all__ = [
    "CIFTI_CHANGE_MAPPING_METADATA",
    "CiftiChangeMappingFromCiftiParamsDict",
    "CiftiChangeMappingFromCiftiParamsDictTagged",
    "CiftiChangeMappingOutputs",
    "CiftiChangeMappingParamsDict",
    "CiftiChangeMappingParamsDictTagged",
    "CiftiChangeMappingScalarParamsDict",
    "CiftiChangeMappingScalarParamsDictTagged",
    "CiftiChangeMappingSeriesParamsDict",
    "CiftiChangeMappingSeriesParamsDictTagged",
    "cifti_change_mapping",
    "cifti_change_mapping_execute",
    "cifti_change_mapping_from_cifti",
    "cifti_change_mapping_params",
    "cifti_change_mapping_scalar",
    "cifti_change_mapping_series",
]
