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

import typing
import pathlib
from styxdefs import *

BORDER_TO_ROIS_METADATA = Metadata(
    id="3bfc45e6cda7bb869f41f04607d7a710d2fab5dd.workbench",
    name="border-to-rois",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_BorderToRoisParamsDictNoTag = typing.TypedDict('_BorderToRoisParamsDictNoTag', {
    "surface": InputPathType,
    "border-file": InputPathType,
    "metric-out": str,
    "name": typing.NotRequired[str | None],
    "include-border": bool,
    "inverse": bool,
})
BorderToRoisParamsDictTagged = typing.TypedDict('BorderToRoisParamsDictTagged', {
    "@type": typing.Literal["workbench/border-to-rois"],
    "surface": InputPathType,
    "border-file": InputPathType,
    "metric-out": str,
    "name": typing.NotRequired[str | None],
    "include-border": bool,
    "inverse": bool,
})
BorderToRoisParamsDict = _BorderToRoisParamsDictNoTag | BorderToRoisParamsDictTagged


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


def border_to_rois_params(
    surface: InputPathType,
    border_file: InputPathType,
    metric_out: str,
    name: str | None = None,
    include_border: bool = False,
    inverse: bool = False,
) -> BorderToRoisParamsDictTagged:
    """
    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.
        include_border: include vertices the border is closest to.
        inverse: use inverse selection (outside border).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/border-to-rois",
        "surface": surface,
        "border-file": border_file,
        "metric-out": metric_out,
        "include-border": include_border,
        "inverse": inverse,
    }
    if name is not None:
        params["name"] = name
    return params


def border_to_rois_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `BorderToRoisParamsDict` 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`')
    if params.get("include-border", False) is None:
        raise StyxValidationError("`include-border` must not be None")
    if not isinstance(params["include-border"], bool):
        raise StyxValidationError(f'`include-border` has the wrong type: Received `{type(params.get("include-border", False))}` expected `bool`')
    if params.get("inverse", False) is None:
        raise StyxValidationError("`inverse` must not be None")
    if not isinstance(params["inverse"], bool):
        raise StyxValidationError(f'`inverse` has the wrong type: Received `{type(params.get("inverse", False))}` expected `bool`')


def border_to_rois_cargs(
    params: BorderToRoisParamsDict,
    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-rois"
    ])
    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)
        ])
    if params.get("include-border", False):
        cargs.append("-include-border")
    if params.get("inverse", False):
        cargs.append("-inverse")
    return cargs


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


def border_to_rois_execute(
    params: BorderToRoisParamsDict,
    runner: Runner | None = None,
) -> BorderToRoisOutputs:
    """
    MAKE METRIC ROIS FROM BORDERS.
    
    By default, draws ROIs inside all borders in the border file, as separate
    metric columns.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderToRoisOutputs`).
    """
    border_to_rois_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(BORDER_TO_ROIS_METADATA)
    params = execution.params(params)
    cargs = border_to_rois_cargs(params, execution)
    ret = border_to_rois_outputs(params, execution)
    execution.run(cargs)
    return ret


def border_to_rois(
    surface: InputPathType,
    border_file: InputPathType,
    metric_out: str,
    name: str | None = None,
    include_border: bool = False,
    inverse: bool = False,
    runner: Runner | None = None,
) -> BorderToRoisOutputs:
    """
    MAKE METRIC ROIS FROM BORDERS.
    
    By default, draws ROIs inside all borders in the border file, as separate
    metric columns.
    
    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.
        include_border: include vertices the border is closest to.
        inverse: use inverse selection (outside border).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `BorderToRoisOutputs`).
    """
    params = border_to_rois_params(
        surface=surface,
        border_file=border_file,
        metric_out=metric_out,
        name=name,
        include_border=include_border,
        inverse=inverse,
    )
    return border_to_rois_execute(params, runner)


__all__ = [
    "BORDER_TO_ROIS_METADATA",
    "BorderToRoisOutputs",
    "BorderToRoisParamsDict",
    "BorderToRoisParamsDictTagged",
    "border_to_rois",
    "border_to_rois_execute",
    "border_to_rois_params",
]
