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

import typing
import pathlib
from styxdefs import *

SCENE_FILE_MERGE_METADATA = Metadata(
    id="72ce88135b0199024083ada6e5b4934b29d0f4bf.workbench",
    name="scene-file-merge",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SceneFileMergeUpToParamsDictNoTag = typing.TypedDict('_SceneFileMergeUpToParamsDictNoTag', {
    "last-column": str,
    "reverse": bool,
})
SceneFileMergeUpToParamsDictTagged = typing.TypedDict('SceneFileMergeUpToParamsDictTagged', {
    "@type": typing.Literal["up-to"],
    "last-column": str,
    "reverse": bool,
})
SceneFileMergeUpToParamsDict = _SceneFileMergeUpToParamsDictNoTag | SceneFileMergeUpToParamsDictTagged


_SceneFileMergeSceneParamsDictNoTag = typing.TypedDict('_SceneFileMergeSceneParamsDictNoTag', {
    "scene": str,
    "up-to": typing.NotRequired[SceneFileMergeUpToParamsDict | None],
})
SceneFileMergeSceneParamsDictTagged = typing.TypedDict('SceneFileMergeSceneParamsDictTagged', {
    "@type": typing.Literal["scene"],
    "scene": str,
    "up-to": typing.NotRequired[SceneFileMergeUpToParamsDict | None],
})
SceneFileMergeSceneParamsDict = _SceneFileMergeSceneParamsDictNoTag | SceneFileMergeSceneParamsDictTagged


_SceneFileMergeSceneFileParamsDictNoTag = typing.TypedDict('_SceneFileMergeSceneFileParamsDictNoTag', {
    "scene-file": str,
    "scene": typing.NotRequired[list[SceneFileMergeSceneParamsDict] | None],
})
SceneFileMergeSceneFileParamsDictTagged = typing.TypedDict('SceneFileMergeSceneFileParamsDictTagged', {
    "@type": typing.Literal["scene-file"],
    "scene-file": str,
    "scene": typing.NotRequired[list[SceneFileMergeSceneParamsDict] | None],
})
SceneFileMergeSceneFileParamsDict = _SceneFileMergeSceneFileParamsDictNoTag | SceneFileMergeSceneFileParamsDictTagged


_SceneFileMergeParamsDictNoTag = typing.TypedDict('_SceneFileMergeParamsDictNoTag', {
    "scene-file-out": str,
    "scene-file": typing.NotRequired[list[SceneFileMergeSceneFileParamsDict] | None],
})
SceneFileMergeParamsDictTagged = typing.TypedDict('SceneFileMergeParamsDictTagged', {
    "@type": typing.Literal["workbench/scene-file-merge"],
    "scene-file-out": str,
    "scene-file": typing.NotRequired[list[SceneFileMergeSceneFileParamsDict] | None],
})
SceneFileMergeParamsDict = _SceneFileMergeParamsDictNoTag | SceneFileMergeParamsDictTagged


def scene_file_merge_up_to(
    last_column: str,
    reverse: bool = False,
) -> SceneFileMergeUpToParamsDictTagged:
    """
    Build parameters.
    
    Args:
        last_column: the number or name of the last scene to include.
        reverse: use the range in reverse order.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "up-to",
        "last-column": last_column,
        "reverse": reverse,
    }
    return params


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


def scene_file_merge_up_to_cargs(
    params: SceneFileMergeUpToParamsDict,
    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([
        "-up-to",
        params.get("last-column", None)
    ])
    if params.get("reverse", False):
        cargs.append("-reverse")
    return cargs


def scene_file_merge_scene(
    scene: str,
    up_to: SceneFileMergeUpToParamsDict | None = None,
) -> SceneFileMergeSceneParamsDictTagged:
    """
    Build parameters.
    
    Args:
        scene: the scene number or name.
        up_to: use an inclusive range of scenes.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "scene",
        "scene": scene,
    }
    if up_to is not None:
        params["up-to"] = up_to
    return params


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


def scene_file_merge_scene_cargs(
    params: SceneFileMergeSceneParamsDict,
    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([
        "-scene",
        params.get("scene", None),
        *(scene_file_merge_up_to_cargs(params.get("up-to", None), execution) if (params.get("up-to", None) is not None) else [])
    ])
    return cargs


def scene_file_merge_scene_file(
    scene_file: str,
    scene: list[SceneFileMergeSceneParamsDict] | None = None,
) -> SceneFileMergeSceneFileParamsDictTagged:
    """
    Build parameters.
    
    Args:
        scene_file: the input scene file.
        scene: specify a scene to use.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "scene-file",
        "scene-file": scene_file,
    }
    if scene is not None:
        params["scene"] = scene
    return params


def scene_file_merge_scene_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SceneFileMergeSceneFileParamsDict` 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("scene-file", None) is None:
        raise StyxValidationError("`scene-file` must not be None")
    if not isinstance(params["scene-file"], str):
        raise StyxValidationError(f'`scene-file` has the wrong type: Received `{type(params.get("scene-file", None))}` expected `str`')
    if params.get("scene", None) is not None:
        if not isinstance(params["scene"], list):
            raise StyxValidationError(f'`scene` has the wrong type: Received `{type(params.get("scene", None))}` expected `list[SceneFileMergeSceneParamsDict] | None`')
        for e in params["scene"]:
            scene_file_merge_scene_validate(e)


def scene_file_merge_scene_file_cargs(
    params: SceneFileMergeSceneFileParamsDict,
    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([
        "-scene-file",
        params.get("scene-file", None),
        *([a for c in [scene_file_merge_scene_cargs(s, execution) for s in params.get("scene", None)] for a in c] if (params.get("scene", None) is not None) else [])
    ])
    return cargs


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


def scene_file_merge_params(
    scene_file_out: str,
    scene_file: list[SceneFileMergeSceneFileParamsDict] | None = None,
) -> SceneFileMergeParamsDictTagged:
    """
    Build parameters.
    
    Args:
        scene_file_out: output - the output scene file.
        scene_file: specify a scene file to use scenes from.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/scene-file-merge",
        "scene-file-out": scene_file_out,
    }
    if scene_file is not None:
        params["scene-file"] = scene_file
    return params


def scene_file_merge_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SceneFileMergeParamsDict` 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("scene-file-out", None) is None:
        raise StyxValidationError("`scene-file-out` must not be None")
    if not isinstance(params["scene-file-out"], str):
        raise StyxValidationError(f'`scene-file-out` has the wrong type: Received `{type(params.get("scene-file-out", None))}` expected `str`')
    if params.get("scene-file", None) is not None:
        if not isinstance(params["scene-file"], list):
            raise StyxValidationError(f'`scene-file` has the wrong type: Received `{type(params.get("scene-file", None))}` expected `list[SceneFileMergeSceneFileParamsDict] | None`')
        for e in params["scene-file"]:
            scene_file_merge_scene_file_validate(e)


def scene_file_merge_cargs(
    params: SceneFileMergeParamsDict,
    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",
        "-scene-file-merge"
    ])
    cargs.append(params.get("scene-file-out", None))
    if params.get("scene-file", None) is not None:
        cargs.extend([a for c in [scene_file_merge_scene_file_cargs(s, execution) for s in params.get("scene-file", None)] for a in c])
    return cargs


def scene_file_merge_outputs(
    params: SceneFileMergeParamsDict,
    execution: Execution,
) -> SceneFileMergeOutputs:
    """
    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 = SceneFileMergeOutputs(
        root=execution.output_file("."),
    )
    return ret


def scene_file_merge_execute(
    params: SceneFileMergeParamsDict,
    runner: Runner | None = None,
) -> SceneFileMergeOutputs:
    """
    REARRANGE SCENES INTO A NEW FILE.
    
    Takes one or more scene files and constructs a new scene file by
    concatenating specified scenes from them.
    
    Example: wb_command -scene-file-merge out.scene -scene-file first.scene
    -scene 1 -scene-file second.scene
    
    This example would take the first scene from first.scene, followed by all
    scenes from second.scene, and write these scenes to out.scene.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SceneFileMergeOutputs`).
    """
    scene_file_merge_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SCENE_FILE_MERGE_METADATA)
    params = execution.params(params)
    cargs = scene_file_merge_cargs(params, execution)
    ret = scene_file_merge_outputs(params, execution)
    execution.run(cargs)
    return ret


def scene_file_merge(
    scene_file_out: str,
    scene_file: list[SceneFileMergeSceneFileParamsDict] | None = None,
    runner: Runner | None = None,
) -> SceneFileMergeOutputs:
    """
    REARRANGE SCENES INTO A NEW FILE.
    
    Takes one or more scene files and constructs a new scene file by
    concatenating specified scenes from them.
    
    Example: wb_command -scene-file-merge out.scene -scene-file first.scene
    -scene 1 -scene-file second.scene
    
    This example would take the first scene from first.scene, followed by all
    scenes from second.scene, and write these scenes to out.scene.
    
    Args:
        scene_file_out: output - the output scene file.
        scene_file: specify a scene file to use scenes from.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SceneFileMergeOutputs`).
    """
    params = scene_file_merge_params(
        scene_file_out=scene_file_out,
        scene_file=scene_file,
    )
    return scene_file_merge_execute(params, runner)


__all__ = [
    "SCENE_FILE_MERGE_METADATA",
    "SceneFileMergeOutputs",
    "SceneFileMergeParamsDict",
    "SceneFileMergeParamsDictTagged",
    "SceneFileMergeSceneFileParamsDict",
    "SceneFileMergeSceneFileParamsDictTagged",
    "SceneFileMergeSceneParamsDict",
    "SceneFileMergeSceneParamsDictTagged",
    "SceneFileMergeUpToParamsDict",
    "SceneFileMergeUpToParamsDictTagged",
    "scene_file_merge",
    "scene_file_merge_execute",
    "scene_file_merge_params",
    "scene_file_merge_scene",
    "scene_file_merge_scene_file",
    "scene_file_merge_up_to",
]
