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

import typing
import pathlib
from styxdefs import *
import dataclasses

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


@dataclasses.dataclass
class BorderMergeUpTo:
    """
    use an inclusive range of borders.
    """
    last_border: str
    """the number or name of the last column to include"""
    opt_reverse: bool = False
    """use the range in reverse order"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-up-to")
        cargs.append(self.last_border)
        if self.opt_reverse:
            cargs.append("-reverse")
        return cargs


@dataclasses.dataclass
class BorderMergeSelect:
    """
    select a single border to use.
    """
    border: str
    """the border number or name"""
    up_to: BorderMergeUpTo | None = None
    """use an inclusive range of borders"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-select")
        cargs.append(self.border)
        if self.up_to is not None:
            cargs.extend(self.up_to.run(execution))
        return cargs


@dataclasses.dataclass
class BorderMergeBorder:
    """
    specify an input border file.
    """
    border_file_in: InputPathType
    """a border file to use borders from"""
    select_: list[BorderMergeSelect] | None = None
    """select a single border to use"""
    
    def run(
        self,
        execution: Execution,
    ) -> list[str]:
        """
        Build command line arguments. This method is called by the main command.
        
        Args:
            execution: The execution object.
        Returns:
            Command line arguments
        """
        cargs = []
        cargs.append("-border")
        cargs.append(execution.input_file(self.border_file_in))
        if self.select_ is not None:
            cargs.extend([a for c in [s.run(execution) for s in self.select_] for a in c])
        return cargs


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


def border_merge(
    border_file_out: str,
    border: list[BorderMergeBorder] | None = None,
    runner: Runner | None = None,
) -> BorderMergeOutputs:
    """
    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: Washington University School of Medicin
    
    Args:
        border_file_out: the output border file.
        border: specify an input border file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderMergeOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(BORDER_MERGE_METADATA)
    cargs = []
    cargs.append("wb_command")
    cargs.append("-border-merge")
    cargs.append(border_file_out)
    if border is not None:
        cargs.extend([a for c in [s.run(execution) for s in border] for a in c])
    ret = BorderMergeOutputs(
        root=execution.output_file("."),
        border_file_out=execution.output_file(border_file_out),
    )
    execution.run(cargs)
    return ret


__all__ = [
    "BORDER_MERGE_METADATA",
    "BorderMergeBorder",
    "BorderMergeOutputs",
    "BorderMergeSelect",
    "BorderMergeUpTo",
    "border_merge",
]
