"""Core data models."""

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


@dataclass
class Message:
    role: str  # "user" or "assistant"
    content: str
    timestamp: Optional[datetime] = None


@dataclass
class Conversation:
    id: str
    messages: List[Message]
    created: Optional[datetime] = None
    title: str = ""
    platform: str = ""
    metadata: Dict[str, Any] = field(default_factory=dict)

    @property
    def first_prompt(self) -> str:
        for msg in self.messages:
            if msg.role == "user":
                return msg.content
        return ""

    @property
    def message_count(self) -> int:
        return len(self.messages)

    @property
    def week(self) -> Optional[str]:
        if self.created:
            return self.created.strftime("%Y-W%V")
        return None

    @property
    def date_str(self) -> Optional[str]:
        if self.created:
            return self.created.strftime("%Y-%m-%d")
        return None


@dataclass
class DimensionResult:
    name: str
    name_en: str
    score: float  # 0-100
    raw_value: float
    weekly_data: Dict[str, float]
    description: str


@dataclass
class CheckupResult:
    dimensions: Dict[str, DimensionResult]
    total_conversations: int
    weeks: List[str]
    period: str
    insights: List[str]
    platform: str
    raw_analysis: Dict[str, Any] = field(default_factory=dict)
