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

import typing
import pathlib
from styxdefs import *

CIFTI_LABEL_TO_BORDER_METADATA = Metadata(
    id="ad9549859ecd3b88b8cca8704b00cceb77188e6a.workbench",
    name="cifti-label-to-border",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiLabelToBorderBorderParamsDictNoTag = typing.TypedDict('_CiftiLabelToBorderBorderParamsDictNoTag', {
    "surface": InputPathType,
    "border-out": str,
})
CiftiLabelToBorderBorderParamsDictTagged = typing.TypedDict('CiftiLabelToBorderBorderParamsDictTagged', {
    "@type": typing.Literal["border"],
    "surface": InputPathType,
    "border-out": str,
})
CiftiLabelToBorderBorderParamsDict = _CiftiLabelToBorderBorderParamsDictNoTag | CiftiLabelToBorderBorderParamsDictTagged


_CiftiLabelToBorderParamsDictNoTag = typing.TypedDict('_CiftiLabelToBorderParamsDictNoTag', {
    "cifti-in": InputPathType,
    "border": typing.NotRequired[list[CiftiLabelToBorderBorderParamsDict] | None],
    "column": typing.NotRequired[str | None],
    "fraction": typing.NotRequired[float | None],
})
CiftiLabelToBorderParamsDictTagged = typing.TypedDict('CiftiLabelToBorderParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-label-to-border"],
    "cifti-in": InputPathType,
    "border": typing.NotRequired[list[CiftiLabelToBorderBorderParamsDict] | None],
    "column": typing.NotRequired[str | None],
    "fraction": typing.NotRequired[float | None],
})
CiftiLabelToBorderParamsDict = _CiftiLabelToBorderParamsDictNoTag | CiftiLabelToBorderParamsDictTagged


class CiftiLabelToBorderBorderOutputs(typing.NamedTuple):
    """
    Output object returned when calling `list[CiftiLabelToBorderBorderParamsDict] | None(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    border_out: OutputPathType
    """the output border file"""


def cifti_label_to_border_border(
    surface: InputPathType,
    border_out: str,
) -> CiftiLabelToBorderBorderParamsDictTagged:
    """
    Build parameters.
    
    Args:
        surface: the surface to use for neighbor and structure information.
        border_out: the output border file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "border",
        "surface": surface,
        "border-out": border_out,
    }
    return params


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


def cifti_label_to_border_border_cargs(
    params: CiftiLabelToBorderBorderParamsDict,
    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([
        "-border",
        execution.input_file(params.get("surface", None)),
        params.get("border-out", None)
    ])
    return cargs


def cifti_label_to_border_border_outputs(
    params: CiftiLabelToBorderBorderParamsDict,
    execution: Execution,
) -> CiftiLabelToBorderBorderOutputs:
    """
    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 = CiftiLabelToBorderBorderOutputs(
        root=execution.output_file("."),
        border_out=execution.output_file(params.get("border-out", None)),
    )
    return ret


class CiftiLabelToBorderOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiLabelToBorderParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    border: list[CiftiLabelToBorderBorderOutputs] | None
    """Outputs from `cifti_label_to_border_border_outputs`.This is a list of
    outputs with the same length and order as the inputs."""


def cifti_label_to_border_params(
    cifti_in: InputPathType,
    border: list[CiftiLabelToBorderBorderParamsDict] | None = None,
    column: str | None = None,
    fraction: float | None = None,
) -> CiftiLabelToBorderParamsDictTagged:
    """
    Build parameters.
    
    Args:
        cifti_in: the input cifti dlabel file.
        border: specify output file for a surface structure.
        column: select a single column\
            \
            the column number or name.
        fraction: set how far along the edge border points are drawn\
            \
            fraction along edge from inside vertex (default 0.33).
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-label-to-border",
        "cifti-in": cifti_in,
    }
    if border is not None:
        params["border"] = border
    if column is not None:
        params["column"] = column
    if fraction is not None:
        params["fraction"] = fraction
    return params


def cifti_label_to_border_validate(
    params: typing.Any,
) -> None:
    """
    Validate parameters. Throws an error if `params` is not a valid
    `CiftiLabelToBorderParamsDict` 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("cifti-in", None) is None:
        raise StyxValidationError("`cifti-in` must not be None")
    if not isinstance(params["cifti-in"], (pathlib.Path, str)):
        raise StyxValidationError(f'`cifti-in` has the wrong type: Received `{type(params.get("cifti-in", None))}` expected `InputPathType`')
    if params.get("border", None) is not None:
        if not isinstance(params["border"], list):
            raise StyxValidationError(f'`border` has the wrong type: Received `{type(params.get("border", None))}` expected `list[CiftiLabelToBorderBorderParamsDict] | None`')
        for e in params["border"]:
            cifti_label_to_border_border_validate(e)
    if params.get("column", None) is not None:
        if not isinstance(params["column"], str):
            raise StyxValidationError(f'`column` has the wrong type: Received `{type(params.get("column", None))}` expected `str | None`')
    if params.get("fraction", None) is not None:
        if not isinstance(params["fraction"], (float, int)):
            raise StyxValidationError(f'`fraction` has the wrong type: Received `{type(params.get("fraction", None))}` expected `float | None`')


def cifti_label_to_border_cargs(
    params: CiftiLabelToBorderParamsDict,
    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",
        "-cifti-label-to-border"
    ])
    cargs.append(execution.input_file(params.get("cifti-in", None)))
    if params.get("border", None) is not None:
        cargs.extend([a for c in [cifti_label_to_border_border_cargs(s, execution) for s in params.get("border", None)] for a in c])
    if params.get("column", None) is not None:
        cargs.extend([
            "-column",
            params.get("column", None)
        ])
    if params.get("fraction", None) is not None:
        cargs.extend([
            "-placement",
            str(params.get("fraction", None))
        ])
    return cargs


def cifti_label_to_border_outputs(
    params: CiftiLabelToBorderParamsDict,
    execution: Execution,
) -> CiftiLabelToBorderOutputs:
    """
    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 = CiftiLabelToBorderOutputs(
        root=execution.output_file("."),
        border=[cifti_label_to_border_border_outputs(i, execution) if cifti_label_to_border_border_outputs else None for i in params.get("border")] if params.get("border") else None,
    )
    return ret


def cifti_label_to_border_execute(
    params: CiftiLabelToBorderParamsDict,
    runner: Runner | None = None,
) -> CiftiLabelToBorderOutputs:
    """
    DRAW BORDERS AROUND CIFTI LABELS.
    
    For each surface, takes the labels on the matching structure and draws
    borders around the labels. Use -column to only draw borders around one label
    map.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelToBorderOutputs`).
    """
    cifti_label_to_border_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_LABEL_TO_BORDER_METADATA)
    params = execution.params(params)
    cargs = cifti_label_to_border_cargs(params, execution)
    ret = cifti_label_to_border_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_label_to_border(
    cifti_in: InputPathType,
    border: list[CiftiLabelToBorderBorderParamsDict] | None = None,
    column: str | None = None,
    fraction: float | None = None,
    runner: Runner | None = None,
) -> CiftiLabelToBorderOutputs:
    """
    DRAW BORDERS AROUND CIFTI LABELS.
    
    For each surface, takes the labels on the matching structure and draws
    borders around the labels. Use -column to only draw borders around one label
    map.
    
    Args:
        cifti_in: the input cifti dlabel file.
        border: specify output file for a surface structure.
        column: select a single column\
            \
            the column number or name.
        fraction: set how far along the edge border points are drawn\
            \
            fraction along edge from inside vertex (default 0.33).
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelToBorderOutputs`).
    """
    params = cifti_label_to_border_params(
        cifti_in=cifti_in,
        border=border,
        column=column,
        fraction=fraction,
    )
    return cifti_label_to_border_execute(params, runner)


__all__ = [
    "CIFTI_LABEL_TO_BORDER_METADATA",
    "CiftiLabelToBorderBorderOutputs",
    "CiftiLabelToBorderBorderParamsDict",
    "CiftiLabelToBorderBorderParamsDictTagged",
    "CiftiLabelToBorderOutputs",
    "CiftiLabelToBorderParamsDict",
    "CiftiLabelToBorderParamsDictTagged",
    "cifti_label_to_border",
    "cifti_label_to_border_border",
    "cifti_label_to_border_execute",
    "cifti_label_to_border_params",
]
