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

import typing
import pathlib
from styxdefs import *

CIFTI_LABEL_ADJACENCY_METADATA = Metadata(
    id="2e19cd8506381d00a3254296038c79a01dddd353.workbench",
    name="cifti-label-adjacency",
    package="workbench",
    container_image_tag="nx10x/workbench:2.1.0",
)


_CiftiLabelAdjacencyParamsDictNoTag = typing.TypedDict('_CiftiLabelAdjacencyParamsDictNoTag', {
    "label-in": InputPathType,
    "adjacency-out": str,
    "surface": typing.NotRequired[InputPathType | None],
    "surface": typing.NotRequired[InputPathType | None],
    "surface": typing.NotRequired[InputPathType | None],
})
CiftiLabelAdjacencyParamsDictTagged = typing.TypedDict('CiftiLabelAdjacencyParamsDictTagged', {
    "@type": typing.Literal["workbench/cifti-label-adjacency"],
    "label-in": InputPathType,
    "adjacency-out": str,
    "surface": typing.NotRequired[InputPathType | None],
    "surface": typing.NotRequired[InputPathType | None],
    "surface": typing.NotRequired[InputPathType | None],
})
CiftiLabelAdjacencyParamsDict = _CiftiLabelAdjacencyParamsDictNoTag | CiftiLabelAdjacencyParamsDictTagged


class CiftiLabelAdjacencyOutputs(typing.NamedTuple):
    """
    Output object returned when calling `CiftiLabelAdjacencyParamsDict(...)`.
    """
    root: OutputPathType
    """Output root folder. This is the root folder for all outputs."""
    adjacency_out: OutputPathType
    """the output cifti pconn adjacency matrix"""


def cifti_label_adjacency_params(
    label_in: InputPathType,
    adjacency_out: str,
    surface: InputPathType | None = None,
    surface_: InputPathType | None = None,
    surface_2: InputPathType | None = None,
) -> CiftiLabelAdjacencyParamsDictTagged:
    """
    Build parameters.
    
    Args:
        label_in: the input cifti label file.
        adjacency_out: the output cifti pconn adjacency matrix.
        surface: specify the cerebellum surface to use\
            \
            the cerebellum surface file.
        surface_: specify the right surface to use\
            \
            the right surface file.
        surface_2: specify the left surface to use\
            \
            the left surface file.
    Returns:
        Parameter dictionary
    """
    params = {
        "@type": "workbench/cifti-label-adjacency",
        "label-in": label_in,
        "adjacency-out": adjacency_out,
    }
    if surface is not None:
        params["surface"] = surface
    if surface_ is not None:
        params["surface"] = surface_
    if surface_2 is not None:
        params["surface"] = surface_2
    return params


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


def cifti_label_adjacency_cargs(
    params: CiftiLabelAdjacencyParamsDict,
    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-adjacency"
    ])
    cargs.append(execution.input_file(params.get("label-in", None)))
    cargs.append(params.get("adjacency-out", None))
    if params.get("surface", None) is not None:
        cargs.extend([
            "-cerebellum-surface",
            execution.input_file(params.get("surface", None))
        ])
    if params.get("surface", None) is not None:
        cargs.extend([
            "-right-surface",
            execution.input_file(params.get("surface", None))
        ])
    if params.get("surface", None) is not None:
        cargs.extend([
            "-left-surface",
            execution.input_file(params.get("surface", None))
        ])
    return cargs


def cifti_label_adjacency_outputs(
    params: CiftiLabelAdjacencyParamsDict,
    execution: Execution,
) -> CiftiLabelAdjacencyOutputs:
    """
    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 = CiftiLabelAdjacencyOutputs(
        root=execution.output_file("."),
        adjacency_out=execution.output_file(params.get("adjacency-out", None)),
    )
    return ret


def cifti_label_adjacency_execute(
    params: CiftiLabelAdjacencyParamsDict,
    runner: Runner | None = None,
) -> CiftiLabelAdjacencyOutputs:
    """
    MAKE ADJACENCY MATRIX OF A CIFTI LABEL FILE.
    
    Find face-adjacent voxels and connected vertices that have different label
    values, and count them for each pair. Put the resulting counts into a
    parcellated connectivity file, with the diagonal being zero. This gives a
    rough estimate of how long or expansive the border between two labels is.
    
    Args:
        params: The parameters.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelAdjacencyOutputs`).
    """
    cifti_label_adjacency_validate(params)
    runner = runner or get_global_runner()
    execution = runner.start_execution(CIFTI_LABEL_ADJACENCY_METADATA)
    params = execution.params(params)
    cargs = cifti_label_adjacency_cargs(params, execution)
    ret = cifti_label_adjacency_outputs(params, execution)
    execution.run(cargs)
    return ret


def cifti_label_adjacency(
    label_in: InputPathType,
    adjacency_out: str,
    surface: InputPathType | None = None,
    surface_: InputPathType | None = None,
    surface_2: InputPathType | None = None,
    runner: Runner | None = None,
) -> CiftiLabelAdjacencyOutputs:
    """
    MAKE ADJACENCY MATRIX OF A CIFTI LABEL FILE.
    
    Find face-adjacent voxels and connected vertices that have different label
    values, and count them for each pair. Put the resulting counts into a
    parcellated connectivity file, with the diagonal being zero. This gives a
    rough estimate of how long or expansive the border between two labels is.
    
    Args:
        label_in: the input cifti label file.
        adjacency_out: the output cifti pconn adjacency matrix.
        surface: specify the cerebellum surface to use\
            \
            the cerebellum surface file.
        surface_: specify the right surface to use\
            \
            the right surface file.
        surface_2: specify the left surface to use\
            \
            the left surface file.
        runner: Command runner.
    Returns:
        NamedTuple of outputs (described in `CiftiLabelAdjacencyOutputs`).
    """
    params = cifti_label_adjacency_params(
        label_in=label_in,
        adjacency_out=adjacency_out,
        surface=surface,
        surface_=surface_,
        surface_2=surface_2,
    )
    return cifti_label_adjacency_execute(params, runner)


__all__ = [
    "CIFTI_LABEL_ADJACENCY_METADATA",
    "CiftiLabelAdjacencyOutputs",
    "CiftiLabelAdjacencyParamsDict",
    "CiftiLabelAdjacencyParamsDictTagged",
    "cifti_label_adjacency",
    "cifti_label_adjacency_execute",
    "cifti_label_adjacency_params",
]
