import enum
from typing import Required, TypeAlias, TypedDict

import numpy as np
from spacy.tokens.doc import Doc as SpacyDoc
from torch import Tensor


# ** logging
class LoggingLevels(enum.IntEnum):
    DEBUG = 10
    INFO = 20
    WARNING = 30
    ERROR = 40
    CRITICAL = 50


# ** devices
class STFRDeviceTypes(enum.StrEnum):
    CPU = enum.auto()
    GPU = enum.auto()


# ** pipelines
ResultHandling: TypeAlias = list[tuple[bool, str | None]]


class EntryPoints(enum.StrEnum):
    TIMELINE = 'TIMELINE'
    TIMELINE_POST = 'TIMELINE_POSTPROCESSING'
    TK_GRAPH_POST = 'TK-GRAPH_POSTPROCESSING'
    TK_GRAPH_ANALYSIS = 'TK-GRAPH_ANALYSIS'
    TOKEN_ANALYSIS = 'TOKEN_ANALYSIS'


# ** datasets
PandasIndex: TypeAlias = int | np.int64
ObjectID: TypeAlias = int
Embedding: TypeAlias = SpacyDoc | Tensor

# ** graphs
NodeTitle: TypeAlias = str
EdgeWeight: TypeAlias = int


class NodeData(TypedDict):
    id: NodeTitle
    label: NodeTitle


class EdgeData(TypedDict):
    source: NodeTitle
    target: NodeTitle
    weight: EdgeWeight


class WeightData(TypedDict):
    min: EdgeWeight
    max: EdgeWeight


class CytoscapePosition(TypedDict):
    x: int
    y: int


class CytoscapeData(TypedDict, total=False):
    data: Required[EdgeData | NodeData]
    position: CytoscapePosition
    grabbable: bool
    locked: bool
    classes: str


# ** timeline
TimelineCandidates: TypeAlias = dict[ObjectID, tuple[tuple[PandasIndex, ...], ...]]
