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

import typing
import pathlib
from styxdefs import *

ZIP_SCENE_FILE_METADATA = Metadata(
    id="b259c5172b5ae3668ffcdba00a5b5a9f3c90cbb1.workbench",
    name="zip-scene-file",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_ZipSceneFileParamsDictNoTag = typing.TypedDict('_ZipSceneFileParamsDictNoTag', {
    "scene-file": str,
    "extract-folder": str,
    "zip-file": str,
    "directory": typing.NotRequired[str | None],
    "write-scene-file": bool,
    "skip-missing": bool,
})
ZipSceneFileParamsDictTagged = typing.TypedDict('ZipSceneFileParamsDictTagged', {
    "@type": typing.Literal["workbench/zip-scene-file"],
    "scene-file": str,
    "extract-folder": str,
    "zip-file": str,
    "directory": typing.NotRequired[str | None],
    "write-scene-file": bool,
    "skip-missing": bool,
})
ZipSceneFileParamsDict = _ZipSceneFileParamsDictNoTag | ZipSceneFileParamsDictTagged


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


def zip_scene_file_params(
    scene_file: str,
    extract_folder: str,
    zip_file: str,
    directory: str | None = None,
    write_scene_file: bool = False,
    skip_missing: bool = False,
) -> ZipSceneFileParamsDictTagged:
    """
    Build parameters.
    
    Args:
        scene_file: the scene file to make the zip file from.
        extract_folder: the name of the folder created when the zip file is\
            unzipped.
        zip_file: out - the zip file that will be created.
        directory: specify a directory that all data files are somewhere\
            within, this will become the root of the zipfile's directory structure\
            \
            the directory.
        write_scene_file: rewrite the scene file before zipping, to store a new\
            base path or fix extra '..'s in paths that might break.
        skip_missing: any missing files will generate only warnings, and the\
            zip file will be created anyway.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/zip-scene-file",
        "scene-file": scene_file,
        "extract-folder": extract_folder,
        "zip-file": zip_file,
        "write-scene-file": write_scene_file,
        "skip-missing": skip_missing,
    }
    if directory is not None:
        params["directory"] = directory
    return params


def zip_scene_file_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `ZipSceneFileParamsDict` 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("extract-folder", None) is None:
        raise StyxValidationError("`extract-folder` must not be None")
    if not isinstance(params["extract-folder"], str):
        raise StyxValidationError(f'`extract-folder` has the wrong type: Received `{type(params.get("extract-folder", None))}` expected `str`')
    if params.get("zip-file", None) is None:
        raise StyxValidationError("`zip-file` must not be None")
    if not isinstance(params["zip-file"], str):
        raise StyxValidationError(f'`zip-file` has the wrong type: Received `{type(params.get("zip-file", None))}` expected `str`')
    if params.get("directory", None) is not None:
        if not isinstance(params["directory"], str):
            raise StyxValidationError(f'`directory` has the wrong type: Received `{type(params.get("directory", None))}` expected `str | None`')
    if params.get("write-scene-file", False) is None:
        raise StyxValidationError("`write-scene-file` must not be None")
    if not isinstance(params["write-scene-file"], bool):
        raise StyxValidationError(f'`write-scene-file` has the wrong type: Received `{type(params.get("write-scene-file", False))}` expected `bool`')
    if params.get("skip-missing", False) is None:
        raise StyxValidationError("`skip-missing` must not be None")
    if not isinstance(params["skip-missing"], bool):
        raise StyxValidationError(f'`skip-missing` has the wrong type: Received `{type(params.get("skip-missing", False))}` expected `bool`')


def zip_scene_file_cargs(
    params: ZipSceneFileParamsDict,
    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",
        "-zip-scene-file"
    ])
    cargs.append(params.get("scene-file", None))
    cargs.append(params.get("extract-folder", None))
    cargs.append(params.get("zip-file", None))
    if params.get("directory", None) is not None:
        cargs.extend([
            "-base-dir",
            params.get("directory", None)
        ])
    if params.get("write-scene-file", False):
        cargs.append("-write-scene-file")
    if params.get("skip-missing", False):
        cargs.append("-skip-missing")
    return cargs


def zip_scene_file_outputs(
    params: ZipSceneFileParamsDict,
    execution: Execution,
) -> ZipSceneFileOutputs:
    """
    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 = ZipSceneFileOutputs(
        root=execution.output_file("."),
    )
    return ret


def zip_scene_file_execute(
    params: ZipSceneFileParamsDict,
    runner: Runner | None = None,
) -> ZipSceneFileOutputs:
    """
    ZIP A SCENE FILE AND ITS DATA FILES.
    
    If zip-file already exists, it will be overwritten. If -base-dir is not
    specified, the base directory will be automatically set to the lowest level
    directory containing all files. The scene file must contain only relative
    paths, and no data files may be outside the base directory.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ZipSceneFileOutputs`).
    """
    zip_scene_file_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(ZIP_SCENE_FILE_METADATA)
    params = execution.params(params)
    cargs = zip_scene_file_cargs(params, execution)
    ret = zip_scene_file_outputs(params, execution)
    execution.run(cargs)
    return ret


def zip_scene_file(
    scene_file: str,
    extract_folder: str,
    zip_file: str,
    directory: str | None = None,
    write_scene_file: bool = False,
    skip_missing: bool = False,
    runner: Runner | None = None,
) -> ZipSceneFileOutputs:
    """
    ZIP A SCENE FILE AND ITS DATA FILES.
    
    If zip-file already exists, it will be overwritten. If -base-dir is not
    specified, the base directory will be automatically set to the lowest level
    directory containing all files. The scene file must contain only relative
    paths, and no data files may be outside the base directory.
    
    Args:
        scene_file: the scene file to make the zip file from.
        extract_folder: the name of the folder created when the zip file is\
            unzipped.
        zip_file: out - the zip file that will be created.
        directory: specify a directory that all data files are somewhere\
            within, this will become the root of the zipfile's directory structure\
            \
            the directory.
        write_scene_file: rewrite the scene file before zipping, to store a new\
            base path or fix extra '..'s in paths that might break.
        skip_missing: any missing files will generate only warnings, and the\
            zip file will be created anyway.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `ZipSceneFileOutputs`).
    """
    params = zip_scene_file_params(
        scene_file=scene_file,
        extract_folder=extract_folder,
        zip_file=zip_file,
        directory=directory,
        write_scene_file=write_scene_file,
        skip_missing=skip_missing,
    )
    return zip_scene_file_execute(params, runner)


__all__ = [
    "ZIP_SCENE_FILE_METADATA",
    "ZipSceneFileOutputs",
    "ZipSceneFileParamsDict",
    "ZipSceneFileParamsDictTagged",
    "zip_scene_file",
    "zip_scene_file_execute",
    "zip_scene_file_params",
]
