"""Message events for iflow-bot."""

from dataclasses import dataclass, field
from typing import Any, Optional


@dataclass
class InboundMessage:
    """
    Inbound message - from channel to Agent.
    
    Represents a message received from a chat platform (Telegram, Discord, etc.)
    that needs to be processed by the agent.
    """
    channel: str
    """Channel name (telegram, discord, whatsapp, feishu, slack, dingtalk, qq, email, mochat)"""
    
    sender_id: str
    """Sender's unique identifier on the platform"""
    
    chat_id: str
    """Chat/channel/conversation identifier"""
    
    content: str
    """Message text content"""
    
    media: list[str] = field(default_factory=list)
    """Optional list of media URLs (images, files, etc.)"""
    
    metadata: dict[str, Any] = field(default_factory=dict)
    """Channel-specific metadata"""
    
    session_key_override: Optional[str] = None
    """Optional session key override for thread-scoped sessions"""
    
    reply_to_id: Optional[str] = None
    """ID of the message being replied to (if any)"""


@dataclass
class OutboundMessage:
    """
    Outbound message - from Agent to channel.
    
    Represents a message generated by the agent that needs to be
    sent to a chat platform.
    """
    channel: str
    """Target channel name"""
    
    chat_id: str
    """Target chat/channel/conversation identifier"""
    
    content: str
    """Message text content"""
    
    metadata: dict[str, Any] = field(default_factory=dict)
    """Channel-specific metadata and delivery options"""
    
    media: list[str] = field(default_factory=list)
    """List of local file paths to send as media attachments.
    
    Channels that support file sending (e.g. Feishu, Telegram) will
    automatically upload and deliver these files.
    Ported from feishu-iflow-bridge file callback feature.
    """
    
    reply_to_id: Optional[str] = None
    """ID of the message to reply to (if any)"""
    
    def with_progress(self, content: str, tool_hint: bool = False) -> "OutboundMessage":
        """Create a progress update message."""
        return OutboundMessage(
            channel=self.channel,
            chat_id=self.chat_id,
            content=content,
            metadata={**self.metadata, "_progress": True, "_tool_hint": tool_hint},
        )
