"""
Antizipation Engine - Data models, enums, and signal container.
"""

from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Dict, Any, Optional
from enum import Enum


# ==================== Enums & Types ====================

class SuggestionTone(str, Enum):
    """Ton/Dringlichkeit eines Vorschlags."""
    HINT = "hint"  # Sanfter Hinweis
    SUGGESTION = "suggestion"  # Aktiver Vorschlag
    REMINDER = "reminder"  # Erinnerung
    URGENT = "urgent"  # Dringend


class ContextType(str, Enum):
    """Typ eines aktiven Kontexts."""
    EVENT_WINDOW = "event_window"  # Event steht bevor
    ROUTINE = "routine"  # Routine heute
    PHASE = "phase"  # Makro-Phase bedingt
    TIME = "time"  # Zeitbasiert (Ferien, Wochenende)


@dataclass
class Signal:
    """Ein einzelnes Signal aus einer Quelle."""
    name: str
    value: Any
    source: str  # "calendar", "usage", "events", "routines"


@dataclass
class ActiveContext:
    """Ein aktiver Kontext der Vorschlaege beeinflusst."""
    id: str
    context_type: ContextType
    label: str
    data: Dict[str, Any] = field(default_factory=dict)


@dataclass
class Suggestion:
    """Ein generierter Vorschlag."""
    id: str
    title: str
    description: str
    tone: SuggestionTone
    action_url: Optional[str] = None
    badge: Optional[str] = None  # z.B. "in 7 Tagen"
    priority: int = 50  # 0-100, hoeher = wichtiger
    rule_id: str = ""
    icon: str = "lightbulb"


@dataclass
class Signals:
    """Container fuer alle gesammelten Signale."""
    # Zeit/Kalender
    current_week: int = 1
    weeks_since_start: int = 0
    is_weekend: bool = False
    is_before_holidays: bool = False
    days_until_holidays: int = 999

    # Makro-Phase
    macro_phase: str = "onboarding"
    onboarding_completed: bool = False

    # Produktnutzung
    classes_count: int = 0
    has_classes: bool = False
    has_schedule: bool = False

    # Events
    exams_scheduled_count: int = 0
    exams_in_7_days: List[Dict] = field(default_factory=list)
    exams_past_ungraded: List[Dict] = field(default_factory=list)
    upcoming_events: List[Dict] = field(default_factory=list)
    trips_in_30_days: List[Dict] = field(default_factory=list)
    parent_evenings_soon: List[Dict] = field(default_factory=list)

    # Routinen
    routines_today: List[Dict] = field(default_factory=list)
    has_conference_today: bool = False

    # Statistiken (aus Analytics)
    corrections_pending: int = 0
    grades_completion_ratio: float = 0.0
