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

import typing
import pathlib
from styxdefs import *

BORDER_LENGTH_METADATA = Metadata(
    id="cb4f6a9883ab1f8156dad010df4a97753b4a5a6d.workbench",
    name="border-length",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_BorderLengthParamsDictNoTag = typing.TypedDict('_BorderLengthParamsDictNoTag', {
    "border": InputPathType,
    "surface": InputPathType,
    "area-metric": typing.NotRequired[InputPathType | None],
    "hide-border-name": bool,
    "separate-pieces": bool,
})
BorderLengthParamsDictTagged = typing.TypedDict('BorderLengthParamsDictTagged', {
    "@type": typing.Literal["workbench/border-length"],
    "border": InputPathType,
    "surface": InputPathType,
    "area-metric": typing.NotRequired[InputPathType | None],
    "hide-border-name": bool,
    "separate-pieces": bool,
})
BorderLengthParamsDict = _BorderLengthParamsDictNoTag | BorderLengthParamsDictTagged


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


def border_length_params(
    border: InputPathType,
    surface: InputPathType,
    area_metric: InputPathType | None = None,
    hide_border_name: bool = False,
    separate_pieces: bool = False,
) -> BorderLengthParamsDictTagged:
    """
    Build parameters.
    
    Args:
        border: the input border file.
        surface: the surface to measure the borders on.
        area_metric: vertex areas to use instead of computing them from the\
            surface\
            \
            the corrected vertex areas, as a metric.
        hide_border_name: don't print border name before each output.
        separate_pieces: report lengths for multi-part borders as separate\
            numbers.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/border-length",
        "border": border,
        "surface": surface,
        "hide-border-name": hide_border_name,
        "separate-pieces": separate_pieces,
    }
    if area_metric is not None:
        params["area-metric"] = area_metric
    return params


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


def border_length_cargs(
    params: BorderLengthParamsDict,
    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-length"
    ])
    cargs.append(execution.input_file(params.get("border", None)))
    cargs.append(execution.input_file(params.get("surface", None)))
    if params.get("area-metric", None) is not None:
        cargs.extend([
            "-corrected-areas",
            execution.input_file(params.get("area-metric", None))
        ])
    if params.get("hide-border-name", False):
        cargs.append("-hide-border-name")
    if params.get("separate-pieces", False):
        cargs.append("-separate-pieces")
    return cargs


def border_length_outputs(
    params: BorderLengthParamsDict,
    execution: Execution,
) -> BorderLengthOutputs:
    """
    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 = BorderLengthOutputs(
        root=execution.output_file("."),
    )
    return ret


def border_length_execute(
    params: BorderLengthParamsDict,
    runner: Runner | None = None,
) -> BorderLengthOutputs:
    """
    REPORT LENGTH OF BORDERS.
    
    For each border, print its length along the surface, in mm. If a border has
    multiple parts, their lengths are summed before printing, unless
    -separate-pieces is specified.
    
    The -corrected-areas option is intended for when the length is not
    meaningfully measurable on individual surfaces, it is only an approximate
    correction for the reduction in structure of a group average surface.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderLengthOutputs`).
    """
    border_length_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(BORDER_LENGTH_METADATA)
    params = execution.params(params)
    cargs = border_length_cargs(params, execution)
    ret = border_length_outputs(params, execution)
    execution.run(cargs)
    return ret


def border_length(
    border: InputPathType,
    surface: InputPathType,
    area_metric: InputPathType | None = None,
    hide_border_name: bool = False,
    separate_pieces: bool = False,
    runner: Runner | None = None,
) -> BorderLengthOutputs:
    """
    REPORT LENGTH OF BORDERS.
    
    For each border, print its length along the surface, in mm. If a border has
    multiple parts, their lengths are summed before printing, unless
    -separate-pieces is specified.
    
    The -corrected-areas option is intended for when the length is not
    meaningfully measurable on individual surfaces, it is only an approximate
    correction for the reduction in structure of a group average surface.
    
    Args:
        border: the input border file.
        surface: the surface to measure the borders on.
        area_metric: vertex areas to use instead of computing them from the\
            surface\
            \
            the corrected vertex areas, as a metric.
        hide_border_name: don't print border name before each output.
        separate_pieces: report lengths for multi-part borders as separate\
            numbers.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderLengthOutputs`).
    """
    params = border_length_params(
        border=border,
        surface=surface,
        area_metric=area_metric,
        hide_border_name=hide_border_name,
        separate_pieces=separate_pieces,
    )
    return border_length_execute(params, runner)


__all__ = [
    "BORDER_LENGTH_METADATA",
    "BorderLengthOutputs",
    "BorderLengthParamsDict",
    "BorderLengthParamsDictTagged",
    "border_length",
    "border_length_execute",
    "border_length_params",
]
