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

import typing
import pathlib
from styxdefs import *

SPEC_FILE_RELOCATE_METADATA = Metadata(
    id="18d002a145082ef00fd24f099aca16f95fc0b29a.workbench",
    name="spec-file-relocate",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SpecFileRelocateParamsDictNoTag = typing.TypedDict('_SpecFileRelocateParamsDictNoTag', {
    "input-spec": str,
    "output-spec": str,
})
SpecFileRelocateParamsDictTagged = typing.TypedDict('SpecFileRelocateParamsDictTagged', {
    "@type": typing.Literal["workbench/spec-file-relocate"],
    "input-spec": str,
    "output-spec": str,
})
SpecFileRelocateParamsDict = _SpecFileRelocateParamsDictNoTag | SpecFileRelocateParamsDictTagged


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


def spec_file_relocate_params(
    input_spec: str,
    output_spec: str,
) -> SpecFileRelocateParamsDictTagged:
    """
    Build parameters.
    
    Args:
        input_spec: the spec file to use.
        output_spec: output - the new spec file to create.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/spec-file-relocate",
        "input-spec": input_spec,
        "output-spec": output_spec,
    }
    return params


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


def spec_file_relocate_cargs(
    params: SpecFileRelocateParamsDict,
    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-relocate"
    ])
    cargs.append(params.get("input-spec", None))
    cargs.append(params.get("output-spec", None))
    return cargs


def spec_file_relocate_outputs(
    params: SpecFileRelocateParamsDict,
    execution: Execution,
) -> SpecFileRelocateOutputs:
    """
    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 = SpecFileRelocateOutputs(
        root=execution.output_file("."),
    )
    return ret


def spec_file_relocate_execute(
    params: SpecFileRelocateParamsDict,
    runner: Runner | None = None,
) -> SpecFileRelocateOutputs:
    """
    RECREATE SPEC FILE IN NEW LOCATION.
    
    Spec files contain internal relative paths, such that moving or copying a
    spec file will cause it to lose track of the files it refers to. This
    command makes a modified copy of the spec file, changing the relative paths
    to refer to the new relative locations of the files.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SpecFileRelocateOutputs`).
    """
    spec_file_relocate_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SPEC_FILE_RELOCATE_METADATA)
    params = execution.params(params)
    cargs = spec_file_relocate_cargs(params, execution)
    ret = spec_file_relocate_outputs(params, execution)
    execution.run(cargs)
    return ret


def spec_file_relocate(
    input_spec: str,
    output_spec: str,
    runner: Runner | None = None,
) -> SpecFileRelocateOutputs:
    """
    RECREATE SPEC FILE IN NEW LOCATION.
    
    Spec files contain internal relative paths, such that moving or copying a
    spec file will cause it to lose track of the files it refers to. This
    command makes a modified copy of the spec file, changing the relative paths
    to refer to the new relative locations of the files.
    
    Args:
        input_spec: the spec file to use.
        output_spec: output - the new spec file to create.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SpecFileRelocateOutputs`).
    """
    params = spec_file_relocate_params(
        input_spec=input_spec,
        output_spec=output_spec,
    )
    return spec_file_relocate_execute(params, runner)


__all__ = [
    "SPEC_FILE_RELOCATE_METADATA",
    "SpecFileRelocateOutputs",
    "SpecFileRelocateParamsDict",
    "SpecFileRelocateParamsDictTagged",
    "spec_file_relocate",
    "spec_file_relocate_execute",
    "spec_file_relocate_params",
]
