# 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="53685982ac0f6c80b96345649dc3d3bb8389bb5b.boutiques",
    name="border-length",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


BorderLengthParameters = typing.TypedDict('BorderLengthParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/border-length"]],
    "border": InputPathType,
    "surface": InputPathType,
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
    "opt_separate_pieces": bool,
    "opt_hide_border_name": bool,
})
BorderLengthParametersTagged = typing.TypedDict('BorderLengthParametersTagged', {
    "@type": typing.Literal["workbench/border-length"],
    "border": InputPathType,
    "surface": InputPathType,
    "opt_corrected_areas_area_metric": typing.NotRequired[InputPathType | None],
    "opt_separate_pieces": bool,
    "opt_hide_border_name": bool,
})


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


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


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


def border_length_outputs(
    params: BorderLengthParameters,
    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: BorderLengthParameters,
    runner: Runner | None = None,
) -> BorderLengthOutputs:
    """
    border-length
    
    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.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderLengthOutputs`).
    """
    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,
    opt_corrected_areas_area_metric: InputPathType | None = None,
    opt_separate_pieces: bool = False,
    opt_hide_border_name: bool = False,
    runner: Runner | None = None,
) -> BorderLengthOutputs:
    """
    border-length
    
    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.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        border: the input border file.
        surface: the surface to measure the borders on.
        opt_corrected_areas_area_metric: vertex areas to use instead of\
            computing them from the surface: the corrected vertex areas, as a\
            metric.
        opt_separate_pieces: report lengths for multi-part borders as separate\
            numbers.
        opt_hide_border_name: don't print border name before each output.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderLengthOutputs`).
    """
    params = border_length_params(
        border=border,
        surface=surface,
        opt_corrected_areas_area_metric=opt_corrected_areas_area_metric,
        opt_separate_pieces=opt_separate_pieces,
        opt_hide_border_name=opt_hide_border_name,
    )
    return border_length_execute(params, runner)


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