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

import typing
import pathlib
from styxdefs import *

BORDER_RESAMPLE_METADATA = Metadata(
    id="323bcae88f347c08d0669f3360e5db16c8affb3e.workbench",
    name="border-resample",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_BorderResampleParamsDictNoTag = typing.TypedDict('_BorderResampleParamsDictNoTag', {
    "border-in": InputPathType,
    "current-sphere": InputPathType,
    "new-sphere": InputPathType,
    "border-out": str,
})
BorderResampleParamsDictTagged = typing.TypedDict('BorderResampleParamsDictTagged', {
    "@type": typing.Literal["workbench/border-resample"],
    "border-in": InputPathType,
    "current-sphere": InputPathType,
    "new-sphere": InputPathType,
    "border-out": str,
})
BorderResampleParamsDict = _BorderResampleParamsDictNoTag | BorderResampleParamsDictTagged


class BorderResampleOutputs(typing.NamedTuple):
    """
    Output object returned when calling `BorderResampleParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    border_out: OutputPathType
    """the output border file"""


def border_resample_params(
    border_in: InputPathType,
    current_sphere: InputPathType,
    new_sphere: InputPathType,
    border_out: str,
) -> BorderResampleParamsDictTagged:
    """
    Build parameters.
    
    Args:
        border_in: the border file to resample.
        current_sphere: a sphere surface with the mesh that the metric is\
            currently on.
        new_sphere: a sphere surface that is in register with <current-sphere>\
            and has the desired output mesh.
        border_out: the output border file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/border-resample",
        "border-in": border_in,
        "current-sphere": current_sphere,
        "new-sphere": new_sphere,
        "border-out": border_out,
    }
    return params


def border_resample_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `BorderResampleParamsDict` 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("border-in", None) is None:
        raise StyxValidationError("`border-in` must not be None")
    if not isinstance(params["border-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`border-in` has the wrong type: Received `{type(params.get("border-in", None))}` expected `InputPathType`')
    if params.get("current-sphere", None) is None:
        raise StyxValidationError("`current-sphere` must not be None")
    if not isinstance(params["current-sphere"], (pathlib.Path, str)):
        raise StyxValidationError(f'`current-sphere` has the wrong type: Received `{type(params.get("current-sphere", None))}` expected `InputPathType`')
    if params.get("new-sphere", None) is None:
        raise StyxValidationError("`new-sphere` must not be None")
    if not isinstance(params["new-sphere"], (pathlib.Path, str)):
        raise StyxValidationError(f'`new-sphere` has the wrong type: Received `{type(params.get("new-sphere", None))}` expected `InputPathType`')
    if params.get("border-out", None) is None:
        raise StyxValidationError("`border-out` must not be None")
    if not isinstance(params["border-out"], str):
        raise StyxValidationError(f'`border-out` has the wrong type: Received `{type(params.get("border-out", None))}` expected `str`')


def border_resample_cargs(
    params: BorderResampleParamsDict,
    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",
        "-border-resample"
    ])
    cargs.append(execution.input_file(params.get("border-in", None)))
    cargs.append(execution.input_file(params.get("current-sphere", None)))
    cargs.append(execution.input_file(params.get("new-sphere", None)))
    cargs.append(params.get("border-out", None))
    return cargs


def border_resample_outputs(
    params: BorderResampleParamsDict,
    execution: Execution,
) -> BorderResampleOutputs:
    """
    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 = BorderResampleOutputs(
        root=execution.output_file("."),
        border_out=execution.output_file(params.get("border-out", None)),
    )
    return ret


def border_resample_execute(
    params: BorderResampleParamsDict,
    runner: Runner | None = None,
) -> BorderResampleOutputs:
    """
    RESAMPLE A BORDER FILE TO A DIFFERENT MESH.
    
    Resamples a border file, given two spherical surfaces that are in register.
    Only borders that have the same structure as current-sphere will be
    resampled.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderResampleOutputs`).
    """
    border_resample_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(BORDER_RESAMPLE_METADATA)
    params = execution.params(params)
    cargs = border_resample_cargs(params, execution)
    ret = border_resample_outputs(params, execution)
    execution.run(cargs)
    return ret


def border_resample(
    border_in: InputPathType,
    current_sphere: InputPathType,
    new_sphere: InputPathType,
    border_out: str,
    runner: Runner | None = None,
) -> BorderResampleOutputs:
    """
    RESAMPLE A BORDER FILE TO A DIFFERENT MESH.
    
    Resamples a border file, given two spherical surfaces that are in register.
    Only borders that have the same structure as current-sphere will be
    resampled.
    
    Args:
        border_in: the border file to resample.
        current_sphere: a sphere surface with the mesh that the metric is\
            currently on.
        new_sphere: a sphere surface that is in register with <current-sphere>\
            and has the desired output mesh.
        border_out: the output border file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderResampleOutputs`).
    """
    params = border_resample_params(
        border_in=border_in,
        current_sphere=current_sphere,
        new_sphere=new_sphere,
        border_out=border_out,
    )
    return border_resample_execute(params, runner)


__all__ = [
    "BORDER_RESAMPLE_METADATA",
    "BorderResampleOutputs",
    "BorderResampleParamsDict",
    "BorderResampleParamsDictTagged",
    "border_resample",
    "border_resample_execute",
    "border_resample_params",
]
