"""
ViewModel oriented view of messages. Both DMs and Email should be supported from any provider,
via the RoutedMessage abstraction.
"""

from dataclasses import dataclass
from typing import Optional, List, Dict, Union

Url = str
Date = str

MessageId = str

@dataclass
class RoutedAddress:
    address: str
    name: Optional[str]
    avi_icon_url: Optional[Url] = None

@dataclass 
class MessageAttachment:
    content_type: str
    name: Optional[str] = None
    size: Optional[int] = None
    preview_url: Optional[Url] = None
    url: Optional[Url] = None

@dataclass
class RoutedMessage:
    to: List[RoutedAddress]
    from_: RoutedAddress
    date: Date
    msg_id: MessageId
    conversation_id: MessageId
    in_reply_to_id: Optional[MessageId] = None
    subject: Optional[str] = None
    headers: Optional[Dict[str, str]] = None
    cc: Optional[List[RoutedAddress]] = None
    text: Optional[str] = None
    html: Optional[str] = None
    attachments: Optional[List[MessageAttachment]] = None # content type, name, size (fetch by index)
    #references: Optional[List[Tuple[str,MessageId]]] = None # type, msg_id. type = forwarded, replied, quoted. Nostr "e" tag, basically.
    #raw_bytes: Optional[bytes] = None

@dataclass
class Conversation:
    id: str
    participants: List[RoutedAddress]
    messages: List[RoutedMessage] = None