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

import typing
import pathlib
from styxdefs import *

SURFACE_MATCH_METADATA = Metadata(
    id="6335c2c3b01da0e8439ffac4c9d4032ef21fd455.workbench",
    name="surface-match",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_SurfaceMatchParamsDictNoTag = typing.TypedDict('_SurfaceMatchParamsDictNoTag', {
    "Match Surface File": InputPathType,
    "Input Surface File": InputPathType,
    "Output Surface Name": str,
})
SurfaceMatchParamsDictTagged = typing.TypedDict('SurfaceMatchParamsDictTagged', {
    "@type": typing.Literal["workbench/surface-match"],
    "Match Surface File": InputPathType,
    "Input Surface File": InputPathType,
    "Output Surface Name": str,
})
SurfaceMatchParamsDict = _SurfaceMatchParamsDictNoTag | SurfaceMatchParamsDictTagged


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


def surface_match_params(
    match_surface_file: InputPathType,
    input_surface_file: InputPathType,
    output_surface_name: str,
) -> SurfaceMatchParamsDictTagged:
    """
    Build parameters.
    
    Args:
        match_surface_file: Match (Reference) Surface.
        input_surface_file: File containing surface that will be transformed.
        output_surface_name: Surface File after transformation.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/surface-match",
        "Match Surface File": match_surface_file,
        "Input Surface File": input_surface_file,
        "Output Surface Name": output_surface_name,
    }
    return params


def surface_match_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `SurfaceMatchParamsDict` 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("Match Surface File", None) is None:
        raise StyxValidationError("`Match Surface File` must not be None")
    if not isinstance(params["Match Surface File"], (pathlib.Path, str)):
        raise StyxValidationError(f'`Match Surface File` has the wrong type: Received `{type(params.get("Match Surface File", None))}` expected `InputPathType`')
    if params.get("Input Surface File", None) is None:
        raise StyxValidationError("`Input Surface File` must not be None")
    if not isinstance(params["Input Surface File"], (pathlib.Path, str)):
        raise StyxValidationError(f'`Input Surface File` has the wrong type: Received `{type(params.get("Input Surface File", None))}` expected `InputPathType`')
    if params.get("Output Surface Name", None) is None:
        raise StyxValidationError("`Output Surface Name` must not be None")
    if not isinstance(params["Output Surface Name"], str):
        raise StyxValidationError(f'`Output Surface Name` has the wrong type: Received `{type(params.get("Output Surface Name", None))}` expected `str`')


def surface_match_cargs(
    params: SurfaceMatchParamsDict,
    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",
        "-surface-match"
    ])
    cargs.append(execution.input_file(params.get("Match Surface File", None)))
    cargs.append(execution.input_file(params.get("Input Surface File", None)))
    cargs.append(params.get("Output Surface Name", None))
    return cargs


def surface_match_outputs(
    params: SurfaceMatchParamsDict,
    execution: Execution,
) -> SurfaceMatchOutputs:
    """
    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 = SurfaceMatchOutputs(
        root=execution.output_file("."),
    )
    return ret


def surface_match_execute(
    params: SurfaceMatchParamsDict,
    runner: Runner | None = None,
) -> SurfaceMatchOutputs:
    """
    SURFACE MATCH.
    
    The Input Surface File will be transformed so that its coordinate ranges
    (bounding box) match that of the Match Surface File.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceMatchOutputs`).
    """
    surface_match_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(SURFACE_MATCH_METADATA)
    params = execution.params(params)
    cargs = surface_match_cargs(params, execution)
    ret = surface_match_outputs(params, execution)
    execution.run(cargs)
    return ret


def surface_match(
    match_surface_file: InputPathType,
    input_surface_file: InputPathType,
    output_surface_name: str,
    runner: Runner | None = None,
) -> SurfaceMatchOutputs:
    """
    SURFACE MATCH.
    
    The Input Surface File will be transformed so that its coordinate ranges
    (bounding box) match that of the Match Surface File.
    
    Args:
        match_surface_file: Match (Reference) Surface.
        input_surface_file: File containing surface that will be transformed.
        output_surface_name: Surface File after transformation.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `SurfaceMatchOutputs`).
    """
    params = surface_match_params(
        match_surface_file=match_surface_file,
        input_surface_file=input_surface_file,
        output_surface_name=output_surface_name,
    )
    return surface_match_execute(params, runner)


__all__ = [
    "SURFACE_MATCH_METADATA",
    "SurfaceMatchOutputs",
    "SurfaceMatchParamsDict",
    "SurfaceMatchParamsDictTagged",
    "surface_match",
    "surface_match_execute",
    "surface_match_params",
]
