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

import typing
import pathlib
from styxdefs import *

SET_MAP_NAMES_METADATA = Metadata(
    id="05c23caac5c21808cadb7f27b12f6fd3f1d3c1f7.workbench",
    name="set-map-names",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SetMapNamesMapParamsDictNoTag = typing.TypedDict('_SetMapNamesMapParamsDictNoTag', {
    "index": int,
    "new-name": str,
})
SetMapNamesMapParamsDictTagged = typing.TypedDict('SetMapNamesMapParamsDictTagged', {
    "@type": typing.Literal["map"],
    "index": int,
    "new-name": str,
})
SetMapNamesMapParamsDict = _SetMapNamesMapParamsDictNoTag | SetMapNamesMapParamsDictTagged


_SetMapNamesParamsDictNoTag = typing.TypedDict('_SetMapNamesParamsDictNoTag', {
    "data-file": str,
    "map": typing.NotRequired[list[SetMapNamesMapParamsDict] | None],
    "file": typing.NotRequired[str | None],
    "file": typing.NotRequired[str | None],
})
SetMapNamesParamsDictTagged = typing.TypedDict('SetMapNamesParamsDictTagged', {
    "@type": typing.Literal["workbench/set-map-names"],
    "data-file": str,
    "map": typing.NotRequired[list[SetMapNamesMapParamsDict] | None],
    "file": typing.NotRequired[str | None],
    "file": typing.NotRequired[str | None],
})
SetMapNamesParamsDict = _SetMapNamesParamsDictNoTag | SetMapNamesParamsDictTagged


def set_map_names_map(
    index: int,
    new_name: str,
) -> SetMapNamesMapParamsDictTagged:
    """
    Build parameters.
    
    Args:
        index: the map index to change the name of.
        new_name: the name to set for the map.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "map",
        "index": index,
        "new-name": new_name,
    }
    return params


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


def set_map_names_map_cargs(
    params: SetMapNamesMapParamsDict,
    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([
        "-map",
        str(params.get("index", None)),
        params.get("new-name", None)
    ])
    return cargs


class SetMapNamesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `SetMapNamesParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""


def set_map_names_params(
    data_file: str,
    map_: list[SetMapNamesMapParamsDict] | None = None,
    file: str | None = None,
    file_: str | None = None,
) -> SetMapNamesParamsDictTagged:
    """
    Build parameters.
    
    Args:
        data_file: the file to set the map names of.
        map_: specify a map to set the name of.
        file: use the map names from another data file\
            \
            a data file with the same number of maps.
        file_: use a text file to replace all map names\
            \
            text file containing map names, one per line.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/set-map-names",
        "data-file": data_file,
    }
    if map_ is not None:
        params["map"] = map_
    if file is not None:
        params["file"] = file
    if file_ is not None:
        params["file"] = file_
    return params


def set_map_names_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SetMapNamesParamsDict` 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-file", None) is None:
        raise StyxValidationError("`data-file` must not be None")
    if not isinstance(params["data-file"], str):
        raise StyxValidationError(f'`data-file` has the wrong type: Received `{type(params.get("data-file", None))}` expected `str`')
    if params.get("map", None) is not None:
        if not isinstance(params["map"], list):
            raise StyxValidationError(f'`map` has the wrong type: Received `{type(params.get("map", None))}` expected `list[SetMapNamesMapParamsDict] | None`')
        for e in params["map"]:
            set_map_names_map_validate(e)
    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("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 set_map_names_cargs(
    params: SetMapNamesParamsDict,
    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",
        "-set-map-names"
    ])
    cargs.append(params.get("data-file", None))
    if params.get("map", None) is not None:
        cargs.extend([a for c in [set_map_names_map_cargs(s, execution) for s in params.get("map", None)] for a in c])
    if params.get("file", None) is not None:
        cargs.extend([
            "-from-data-file",
            params.get("file", None)
        ])
    if params.get("file", None) is not None:
        cargs.extend([
            "-name-file",
            params.get("file", None)
        ])
    return cargs


def set_map_names_outputs(
    params: SetMapNamesParamsDict,
    execution: Execution,
) -> SetMapNamesOutputs:
    """
    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 = SetMapNamesOutputs(
        root=execution.output_file("."),
    )
    return ret


def set_map_names_execute(
    params: SetMapNamesParamsDict,
    runner: Runner | None = None,
) -> SetMapNamesOutputs:
    """
    SET THE NAME OF ONE OR MORE MAPS IN A FILE.
    
    Sets the name of one or more maps for metric, shape, label, volume, cifti
    scalar or cifti label files. You must specify either -name-file, or
    -from-data-file, or at least one -map option. The three option types are
    mutually exclusive.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SetMapNamesOutputs`).
    """
    set_map_names_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SET_MAP_NAMES_METADATA)
    params = execution.params(params)
    cargs = set_map_names_cargs(params, execution)
    ret = set_map_names_outputs(params, execution)
    execution.run(cargs)
    return ret


def set_map_names(
    data_file: str,
    map_: list[SetMapNamesMapParamsDict] | None = None,
    file: str | None = None,
    file_: str | None = None,
    runner: Runner | None = None,
) -> SetMapNamesOutputs:
    """
    SET THE NAME OF ONE OR MORE MAPS IN A FILE.
    
    Sets the name of one or more maps for metric, shape, label, volume, cifti
    scalar or cifti label files. You must specify either -name-file, or
    -from-data-file, or at least one -map option. The three option types are
    mutually exclusive.
    
    Args:
        data_file: the file to set the map names of.
        map_: specify a map to set the name of.
        file: use the map names from another data file\
            \
            a data file with the same number of maps.
        file_: use a text file to replace all map names\
            \
            text file containing map names, one per line.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SetMapNamesOutputs`).
    """
    params = set_map_names_params(
        data_file=data_file,
        map_=map_,
        file=file,
        file_=file_,
    )
    return set_map_names_execute(params, runner)


__all__ = [
    "SET_MAP_NAMES_METADATA",
    "SetMapNamesMapParamsDict",
    "SetMapNamesMapParamsDictTagged",
    "SetMapNamesOutputs",
    "SetMapNamesParamsDict",
    "SetMapNamesParamsDictTagged",
    "set_map_names",
    "set_map_names_execute",
    "set_map_names_map",
    "set_map_names_params",
]
