"""Data models for ThirdEye."""
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime
import uuid


class Signal(BaseModel):
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    group_id: str
    lens: str = "unknown"  # dev, product, client, community
    type: str  # architecture_decision, tech_debt, etc.
    summary: str
    entities: list[str] = []
    severity: str = "low"  # low, medium, high, critical
    status: str = "unknown"  # proposed, decided, implemented, unresolved
    sentiment: str = "neutral"
    urgency: str = "none"
    raw_quote: str = ""
    source_messages: list[int] = []
    timestamp: str = Field(default_factory=lambda: datetime.utcnow().isoformat())
    keywords: list[str] = []


class Pattern(BaseModel):
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    group_id: str
    type: str  # frequency_spike, knowledge_silo, recurring_issue, sentiment_trend, stale_item
    description: str
    severity: str = "info"  # info, warning, critical
    evidence_signal_ids: list[str] = []
    recommendation: str = ""
    detected_at: str = Field(default_factory=lambda: datetime.utcnow().isoformat())
    is_active: bool = True


class CrossGroupInsight(BaseModel):
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    type: str  # blocked_handoff, conflicting_decision, information_silo, promise_reality_gap, duplicated_effort
    description: str
    group_a: dict = {}  # {name, group_id, evidence}
    group_b: dict = {}
    severity: str = "warning"
    recommendation: str = ""
    detected_at: str = Field(default_factory=lambda: datetime.utcnow().isoformat())
    is_resolved: bool = False


class GroupConfig(BaseModel):
    group_id: str
    group_name: str = ""
    lens_mode: str = "auto"  # auto, dev, product, client, community
    detected_lens: str = "unknown"
    confidence: float = 0.0
    is_active: bool = True
    message_count: int = 0
    signal_count: int = 0
