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

import typing
import pathlib
from styxdefs import *

CIFTI_LABEL_IMPORT_METADATA = Metadata(
    id="ff57f7adfa683ce934248ecdc96b3c5c9f99b22e.boutiques",
    name="cifti-label-import",
    package="workbench",
    container_image_tag="brainlife/connectome_workbench:1.5.0-freesurfer-update",
)


CiftiLabelImportParameters = typing.TypedDict('CiftiLabelImportParameters', {
    "@type": typing.NotRequired[typing.Literal["workbench/cifti-label-import"]],
    "input": InputPathType,
    "label_list_file": str,
    "output": str,
    "opt_discard_others": bool,
    "opt_unlabeled_value_value": typing.NotRequired[int | None],
    "opt_drop_unused_labels": bool,
})
CiftiLabelImportParametersTagged = typing.TypedDict('CiftiLabelImportParametersTagged', {
    "@type": typing.Literal["workbench/cifti-label-import"],
    "input": InputPathType,
    "label_list_file": str,
    "output": str,
    "opt_discard_others": bool,
    "opt_unlabeled_value_value": typing.NotRequired[int | None],
    "opt_drop_unused_labels": bool,
})


class CiftiLabelImportOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiLabelImportParameters(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    output: OutputPathType
    """the output cifti label file"""


def cifti_label_import_params(
    input_: InputPathType,
    label_list_file: str,
    output: str,
    opt_discard_others: bool = False,
    opt_unlabeled_value_value: int | None = None,
    opt_drop_unused_labels: bool = False,
) -> CiftiLabelImportParametersTagged:
    """
    Build parameters.
    
    Args:
        input_: the input cifti file.
        label_list_file: text file containing the values and names for labels.
        output: the output cifti label file.
        opt_discard_others: set any values not mentioned in the label list to\
            the ??? label.
        opt_unlabeled_value_value: set the value that will be interpreted as\
            unlabeled: the numeric value for unlabeled (default 0).
        opt_drop_unused_labels: remove any unused label values from the label\
            table.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-label-import",
        "input": input_,
        "label_list_file": label_list_file,
        "output": output,
        "opt_discard_others": opt_discard_others,
        "opt_drop_unused_labels": opt_drop_unused_labels,
    }
    if opt_unlabeled_value_value is not None:
        params["opt_unlabeled_value_value"] = opt_unlabeled_value_value
    return params


def cifti_label_import_cargs(
    params: CiftiLabelImportParameters,
    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("-cifti-label-import")
    cargs.append(execution.input_file(params.get("input", None)))
    cargs.append(params.get("label_list_file", None))
    cargs.append(params.get("output", None))
    if params.get("opt_discard_others", False):
        cargs.append("-discard-others")
    if params.get("opt_unlabeled_value_value", None) is not None:
        cargs.extend([
            "-unlabeled-value",
            str(params.get("opt_unlabeled_value_value", None))
        ])
    if params.get("opt_drop_unused_labels", False):
        cargs.append("-drop-unused-labels")
    return cargs


def cifti_label_import_outputs(
    params: CiftiLabelImportParameters,
    execution: Execution,
) -> CiftiLabelImportOutputs:
    """
    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 = CiftiLabelImportOutputs(
        root=execution.output_file("."),
        output=execution.output_file(params.get("output", None)),
    )
    return ret


def cifti_label_import_execute(
    params: CiftiLabelImportParameters,
    runner: Runner | None = None,
) -> CiftiLabelImportOutputs:
    """
    cifti-label-import
    
    Make a cifti label file from a cifti file.
    
    Creates a cifti label file from a cifti file with label-like values. You may
    specify the empty string (use "") for <label-list-file>, which will be
    treated as if it is an empty file. The label list file must have the
    following format (2 lines per label):
    
    <labelname>
    <key> <red> <green> <blue> <alpha>
    ...
    
    Label names are specified on a separate line from their value and color, in
    order to let label names contain spaces. Whitespace is trimmed from both
    ends of the label name, but is kept if it is in the middle of a label. Do
    not specify the "unlabeled" key in the file, it is assumed that 0 means not
    labeled unless -unlabeled-value is specified. The value of <key> specifies
    what value in the imported file should be used as this label (these same key
    values are also used in the output file). The values of <red>, <green>,
    <blue> and <alpha> must be integers from 0 to 255, and will specify the
    color the label is drawn as (alpha of 255 means fully opaque, which is
    probably what you want).
    
    By default, it will create new label names with names like LABEL_5 for any
    values encountered that are not mentioned in the list file, specify
    -discard-others to instead set these values to the "unlabeled" key.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelImportOutputs`).
    """
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_LABEL_IMPORT_METADATA)
    params = execution.params(params)
    cargs = cifti_label_import_cargs(params, execution)
    ret = cifti_label_import_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_label_import(
    input_: InputPathType,
    label_list_file: str,
    output: str,
    opt_discard_others: bool = False,
    opt_unlabeled_value_value: int | None = None,
    opt_drop_unused_labels: bool = False,
    runner: Runner | None = None,
) -> CiftiLabelImportOutputs:
    """
    cifti-label-import
    
    Make a cifti label file from a cifti file.
    
    Creates a cifti label file from a cifti file with label-like values. You may
    specify the empty string (use "") for <label-list-file>, which will be
    treated as if it is an empty file. The label list file must have the
    following format (2 lines per label):
    
    <labelname>
    <key> <red> <green> <blue> <alpha>
    ...
    
    Label names are specified on a separate line from their value and color, in
    order to let label names contain spaces. Whitespace is trimmed from both
    ends of the label name, but is kept if it is in the middle of a label. Do
    not specify the "unlabeled" key in the file, it is assumed that 0 means not
    labeled unless -unlabeled-value is specified. The value of <key> specifies
    what value in the imported file should be used as this label (these same key
    values are also used in the output file). The values of <red>, <green>,
    <blue> and <alpha> must be integers from 0 to 255, and will specify the
    color the label is drawn as (alpha of 255 means fully opaque, which is
    probably what you want).
    
    By default, it will create new label names with names like LABEL_5 for any
    values encountered that are not mentioned in the list file, specify
    -discard-others to instead set these values to the "unlabeled" key.
    
    Author: Connectome Workbench Developers
    
    URL: https://github.com/Washington-University/workbench
    
    Args:
        input_: the input cifti file.
        label_list_file: text file containing the values and names for labels.
        output: the output cifti label file.
        opt_discard_others: set any values not mentioned in the label list to\
            the ??? label.
        opt_unlabeled_value_value: set the value that will be interpreted as\
            unlabeled: the numeric value for unlabeled (default 0).
        opt_drop_unused_labels: remove any unused label values from the label\
            table.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelImportOutputs`).
    """
    params = cifti_label_import_params(
        input_=input_,
        label_list_file=label_list_file,
        output=output,
        opt_discard_others=opt_discard_others,
        opt_unlabeled_value_value=opt_unlabeled_value_value,
        opt_drop_unused_labels=opt_drop_unused_labels,
    )
    return cifti_label_import_execute(params, runner)


__all__ = [
    "CIFTI_LABEL_IMPORT_METADATA",
    "CiftiLabelImportOutputs",
    "cifti_label_import",
    "cifti_label_import_execute",
    "cifti_label_import_params",
]
