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

import typing
import pathlib
from styxdefs import *

BORDER_TO_VERTICES_METADATA = Metadata(
    id="3844ea00db2d10878f48538c7a9b40fecdd4a9e0.workbench",
    name="border-to-vertices",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_BorderToVerticesParamsDictNoTag = typing.TypedDict('_BorderToVerticesParamsDictNoTag', {
    "surface": InputPathType,
    "border-file": InputPathType,
    "metric-out": str,
    "name": typing.NotRequired[str | None],
})
BorderToVerticesParamsDictTagged = typing.TypedDict('BorderToVerticesParamsDictTagged', {
    "@type": typing.Literal["workbench/border-to-vertices"],
    "surface": InputPathType,
    "border-file": InputPathType,
    "metric-out": str,
    "name": typing.NotRequired[str | None],
})
BorderToVerticesParamsDict = _BorderToVerticesParamsDictNoTag | BorderToVerticesParamsDictTagged


class BorderToVerticesOutputs(typing.NamedTuple):
    """
    Output object returned when calling `BorderToVerticesParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    metric_out: OutputPathType
    """the output metric file"""


def border_to_vertices_params(
    surface: InputPathType,
    border_file: InputPathType,
    metric_out: str,
    name: str | None = None,
) -> BorderToVerticesParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the surface the borders are drawn on.
        border_file: the border file.
        metric_out: the output metric file.
        name: create ROI for only one border\
            \
            the name of the border.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/border-to-vertices",
        "surface": surface,
        "border-file": border_file,
        "metric-out": metric_out,
    }
    if name is not None:
        params["name"] = name
    return params


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


def border_to_vertices_cargs(
    params: BorderToVerticesParamsDict,
    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-to-vertices"
    ])
    cargs.append(execution.input_file(params.get("surface", None)))
    cargs.append(execution.input_file(params.get("border-file", None)))
    cargs.append(params.get("metric-out", None))
    if params.get("name", None) is not None:
        cargs.extend([
            "-border",
            params.get("name", None)
        ])
    return cargs


def border_to_vertices_outputs(
    params: BorderToVerticesParamsDict,
    execution: Execution,
) -> BorderToVerticesOutputs:
    """
    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 = BorderToVerticesOutputs(
        root=execution.output_file("."),
        metric_out=execution.output_file(params.get("metric-out", None)),
    )
    return ret


def border_to_vertices_execute(
    params: BorderToVerticesParamsDict,
    runner: Runner | None = None,
) -> BorderToVerticesOutputs:
    """
    DRAW BORDERS AS VERTICES IN A METRIC FILE.
    
    Outputs a metric with 1s on vertices that follow a border, and 0s elsewhere.
    By default, a separate metric column is created for each border.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderToVerticesOutputs`).
    """
    border_to_vertices_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(BORDER_TO_VERTICES_METADATA)
    params = execution.params(params)
    cargs = border_to_vertices_cargs(params, execution)
    ret = border_to_vertices_outputs(params, execution)
    execution.run(cargs)
    return ret


def border_to_vertices(
    surface: InputPathType,
    border_file: InputPathType,
    metric_out: str,
    name: str | None = None,
    runner: Runner | None = None,
) -> BorderToVerticesOutputs:
    """
    DRAW BORDERS AS VERTICES IN A METRIC FILE.
    
    Outputs a metric with 1s on vertices that follow a border, and 0s elsewhere.
    By default, a separate metric column is created for each border.
    
    Args:
        surface: the surface the borders are drawn on.
        border_file: the border file.
        metric_out: the output metric file.
        name: create ROI for only one border\
            \
            the name of the border.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderToVerticesOutputs`).
    """
    params = border_to_vertices_params(
        surface=surface,
        border_file=border_file,
        metric_out=metric_out,
        name=name,
    )
    return border_to_vertices_execute(params, runner)


__all__ = [
    "BORDER_TO_VERTICES_METADATA",
    "BorderToVerticesOutputs",
    "BorderToVerticesParamsDict",
    "BorderToVerticesParamsDictTagged",
    "border_to_vertices",
    "border_to_vertices_execute",
    "border_to_vertices_params",
]
