from abc import ABC, abstractmethod # 抽象类，抽象方法
from typing import List, Optional
from ..message import Message

class MessageStorage(ABC):
    """抽象类：信息存储。其中信息条数设置限制"""
    
    @abstractmethod
    def add(self, message: Message) -> bool:
        """添加消息到储存"""
        pass
    
    @abstractmethod
    def get_recent(self, roomid: str, limit: int = 1000) -> List[Message]:
        """获取最近N条消息"""
        pass
    
    @abstractmethod
    def get_by_id(self, msgid: str) -> Optional[Message]:
        """根据ID获取单条消息"""
        pass
    
    @abstractmethod
    def get_by_sender(self, roomid: str, sender_id: str, limit: int = 1000) -> List[Message]:
        """获取特定发送者的消息"""
        pass
    
    @abstractmethod
    def get_replies(self, roomid: str, replyto: str, limit: int = 200) -> List[Message]:
        """获取某条消息的回复列表"""
        pass
    
    @abstractmethod
    def clear(self, roomid: str):
        """清空指定房间的消息"""
        pass
    
    @abstractmethod
    def count(self, roomid: str) -> int:
        """获取消息总数"""
        pass
    
    @abstractmethod
    def close(self):
        """关闭存储连接"""
        pass