"""Type definitions for Meowdel API"""

from typing import List, Optional, Any, Dict
from dataclasses import dataclass, asdict


@dataclass
class Message:
    """Conversation message"""
    role: str  # "user" or "assistant"
    content: str

    def dict(self) -> Dict[str, str]:
        return asdict(self)


@dataclass
class ChatRequest:
    """Chat request payload"""
    message: str
    personality: str = "mittens"
    useBrainContext: bool = False
    conversationHistory: List[Dict[str, str]] = None

    def __post_init__(self):
        if self.conversationHistory is None:
            self.conversationHistory = []

    def dict(self) -> Dict[str, Any]:
        return {
            "message": self.message,
            "personality": self.personality,
            "useBrainContext": self.useBrainContext,
            "conversationHistory": self.conversationHistory,
        }


@dataclass
class ChatResponse:
    """Chat response from API"""
    message: str
    personality: str
    timestamp: Optional[str] = None
    brainContextUsed: bool = False
    tokensUsed: Optional[int] = None

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "ChatResponse":
        return cls(**data)


@dataclass
class CombineRequest:
    """Combine operations request"""
    query: str
    operations: List[str]
    primaryPersonality: str = "mittens"
    secondaryPersonality: str = "professor"

    def dict(self) -> Dict[str, Any]:
        return asdict(self)


@dataclass
class CombineResponse:
    """Combined operations response"""
    result: str
    operations: List[str]
    primaryPersonality: str
    secondaryPersonality: str
    timestamp: Optional[str] = None
    tokensUsed: Optional[int] = None

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> "CombineResponse":
        return cls(**data)
