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

import typing
import pathlib
from styxdefs import *

SPEC_FILE_MERGE_METADATA = Metadata(
    id="85ecceaff1fc0a1530a0d4627dab53d2a72a20ea.workbench",
    name="spec-file-merge",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SpecFileMergeParamsDictNoTag = typing.TypedDict('_SpecFileMergeParamsDictNoTag', {
    "spec-1": str,
    "spec-2": str,
    "out-spec": str,
})
SpecFileMergeParamsDictTagged = typing.TypedDict('SpecFileMergeParamsDictTagged', {
    "@type": typing.Literal["workbench/spec-file-merge"],
    "spec-1": str,
    "spec-2": str,
    "out-spec": str,
})
SpecFileMergeParamsDict = _SpecFileMergeParamsDictNoTag | SpecFileMergeParamsDictTagged


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


def spec_file_merge_params(
    spec_1: str,
    spec_2: str,
    out_spec: str,
) -> SpecFileMergeParamsDictTagged:
    """
    Build parameters.
    
    Args:
        spec_1: first spec file to merge.
        spec_2: second spec file to merge.
        out_spec: output - output spec file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/spec-file-merge",
        "spec-1": spec_1,
        "spec-2": spec_2,
        "out-spec": out_spec,
    }
    return params


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


def spec_file_merge_cargs(
    params: SpecFileMergeParamsDict,
    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",
        "-spec-file-merge"
    ])
    cargs.append(params.get("spec-1", None))
    cargs.append(params.get("spec-2", None))
    cargs.append(params.get("out-spec", None))
    return cargs


def spec_file_merge_outputs(
    params: SpecFileMergeParamsDict,
    execution: Execution,
) -> SpecFileMergeOutputs:
    """
    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 = SpecFileMergeOutputs(
        root=execution.output_file("."),
    )
    return ret


def spec_file_merge_execute(
    params: SpecFileMergeParamsDict,
    runner: Runner | None = None,
) -> SpecFileMergeOutputs:
    """
    MERGE TWO SPEC FILES INTO ONE.
    
    The output spec file contains every file that is in either of the input spec
    files.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SpecFileMergeOutputs`).
    """
    spec_file_merge_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SPEC_FILE_MERGE_METADATA)
    params = execution.params(params)
    cargs = spec_file_merge_cargs(params, execution)
    ret = spec_file_merge_outputs(params, execution)
    execution.run(cargs)
    return ret


def spec_file_merge(
    spec_1: str,
    spec_2: str,
    out_spec: str,
    runner: Runner | None = None,
) -> SpecFileMergeOutputs:
    """
    MERGE TWO SPEC FILES INTO ONE.
    
    The output spec file contains every file that is in either of the input spec
    files.
    
    Args:
        spec_1: first spec file to merge.
        spec_2: second spec file to merge.
        out_spec: output - output spec file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SpecFileMergeOutputs`).
    """
    params = spec_file_merge_params(
        spec_1=spec_1,
        spec_2=spec_2,
        out_spec=out_spec,
    )
    return spec_file_merge_execute(params, runner)


__all__ = [
    "SPEC_FILE_MERGE_METADATA",
    "SpecFileMergeOutputs",
    "SpecFileMergeParamsDict",
    "SpecFileMergeParamsDictTagged",
    "spec_file_merge",
    "spec_file_merge_execute",
    "spec_file_merge_params",
]
