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

import typing
import pathlib
from styxdefs import *

BORDER_MERGE_METADATA = Metadata(
    id="7be2470075824ac407debd55d81755eb8f1ddd15.boutiques",
    name="border-merge",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


BorderMergeUpToParameters = typing.TypedDict('BorderMergeUpToParameters', {
    "@type": typing.NotRequired[typing.Literal["up_to"]],
    "last_border": str,
    "opt_reverse": bool,
})
BorderMergeUpToParametersTagged = typing.TypedDict('BorderMergeUpToParametersTagged', {
    "@type": typing.Literal["up_to"],
    "last_border": str,
    "opt_reverse": bool,
})


BorderMergeSelectParameters = typing.TypedDict('BorderMergeSelectParameters', {
    "@type": typing.NotRequired[typing.Literal["select"]],
    "border": str,
    "up_to": typing.NotRequired[BorderMergeUpToParameters | None],
})
BorderMergeSelectParametersTagged = typing.TypedDict('BorderMergeSelectParametersTagged', {
    "@type": typing.Literal["select"],
    "border": str,
    "up_to": typing.NotRequired[BorderMergeUpToParameters | None],
})


BorderMergeBorderParameters = typing.TypedDict('BorderMergeBorderParameters', {
    "@type": typing.NotRequired[typing.Literal["border"]],
    "border_file_in": InputPathType,
    "select": typing.NotRequired[list[BorderMergeSelectParameters] | None],
})
BorderMergeBorderParametersTagged = typing.TypedDict('BorderMergeBorderParametersTagged', {
    "@type": typing.Literal["border"],
    "border_file_in": InputPathType,
    "select": typing.NotRequired[list[BorderMergeSelectParameters] | None],
})


BorderMergeParameters = typing.TypedDict('BorderMergeParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/border-merge"]],
    "border_file_out": str,
    "border": typing.NotRequired[list[BorderMergeBorderParameters] | None],
})
BorderMergeParametersTagged = typing.TypedDict('BorderMergeParametersTagged', {
    "@type": typing.Literal["workbench/border-merge"],
    "border_file_out": str,
    "border": typing.NotRequired[list[BorderMergeBorderParameters] | None],
})


def border_merge_up_to_params(
    last_border: str,
    opt_reverse: bool = False,
) -> BorderMergeUpToParametersTagged:
    """
    Build parameters.
    
    Args:
        last_border: the number or name of the last column to include.
        opt_reverse: use the range in reverse order.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "up_to",
        "last_border": last_border,
        "opt_reverse": opt_reverse,
    }
    return params


def border_merge_up_to_cargs(
    params: BorderMergeUpToParameters,
    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("-up-to")
    cargs.append(params.get("last_border", None))
    if params.get("opt_reverse", False):
        cargs.append("-reverse")
    return cargs


def border_merge_select_params(
    border: str,
    up_to: BorderMergeUpToParameters | None = None,
) -> BorderMergeSelectParametersTagged:
    """
    Build parameters.
    
    Args:
        border: the border number or name.
        up_to: use an inclusive range of borders.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "select",
        "border": border,
    }
    if up_to is not None:
        params["up_to"] = up_to
    return params


def border_merge_select_cargs(
    params: BorderMergeSelectParameters,
    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("-select")
    cargs.append(params.get("border", None))
    if params.get("up_to", None) is not None:
        cargs.extend(border_merge_up_to_cargs(params.get("up_to", None), execution))
    return cargs


def border_merge_border_params(
    border_file_in: InputPathType,
    select_: list[BorderMergeSelectParameters] | None = None,
) -> BorderMergeBorderParametersTagged:
    """
    Build parameters.
    
    Args:
        border_file_in: a border file to use borders from.
        select_: select a single border to use.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "border",
        "border_file_in": border_file_in,
    }
    if select_ is not None:
        params["select"] = select_
    return params


def border_merge_border_cargs(
    params: BorderMergeBorderParameters,
    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("-border")
    cargs.append(execution.input_file(params.get("border_file_in", None)))
    if params.get("select", None) is not None:
        cargs.extend([a for c in [border_merge_select_cargs(s, execution) for s in params.get("select", None)] for a in c])
    return cargs


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


def border_merge_params(
    border_file_out: str,
    border: list[BorderMergeBorderParameters] | None = None,
) -> BorderMergeParametersTagged:
    """
    Build parameters.
    
    Args:
        border_file_out: the output border file.
        border: specify an input border file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/border-merge",
        "border_file_out": border_file_out,
    }
    if border is not None:
        params["border"] = border
    return params


def border_merge_cargs(
    params: BorderMergeParameters,
    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-merge")
    cargs.append(params.get("border_file_out", None))
    if params.get("border", None) is not None:
        cargs.extend([a for c in [border_merge_border_cargs(s, execution) for s in params.get("border", None)] for a in c])
    return cargs


def border_merge_outputs(
    params: BorderMergeParameters,
    execution: Execution,
) -> BorderMergeOutputs:
    """
    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 = BorderMergeOutputs(
        root=execution.output_file("."),
        border_file_out=execution.output_file(params.get("border_file_out", None)),
    )
    return ret


def border_merge_execute(
    params: BorderMergeParameters,
    runner: Runner | None = None,
) -> BorderMergeOutputs:
    """
    border-merge
    
    Merge border files into a new file.
    
    Takes one or more border files and makes a new border file from the borders
    in them.
    
    Example: wb_command -border-merge out.border -border first.border -select 1
    -border second.border
    
    This example would take the first border from first.border, followed by all
    borders from second.border, and write these to out.border.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderMergeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(BORDER_MERGE_METADATA)
    params = execution.params(params)
    cargs = border_merge_cargs(params, execution)
    ret = border_merge_outputs(params, execution)
    execution.run(cargs)
    return ret


def border_merge(
    border_file_out: str,
    border: list[BorderMergeBorderParameters] | None = None,
    runner: Runner | None = None,
) -> BorderMergeOutputs:
    """
    border-merge
    
    Merge border files into a new file.
    
    Takes one or more border files and makes a new border file from the borders
    in them.
    
    Example: wb_command -border-merge out.border -border first.border -select 1
    -border second.border
    
    This example would take the first border from first.border, followed by all
    borders from second.border, and write these to out.border.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        border_file_out: the output border file.
        border: specify an input border file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderMergeOutputs`).
    """
    params = border_merge_params(
        border_file_out=border_file_out,
        border=border,
    )
    return border_merge_execute(params, runner)


__all__ = [
    "BORDER_MERGE_METADATA",
    "BorderMergeOutputs",
    "border_merge",
    "border_merge_border_params",
    "border_merge_execute",
    "border_merge_params",
    "border_merge_select_params",
    "border_merge_up_to_params",
]
