package com.sikey.wa04.business.domain.adapter;

import com.sikey.wa04.business.domain.entity.ChatSessionId;
import com.sikey.wa04.business.domain.entity.UserId;
import com.sikey.wa04.business.domain.entity.message.Message;
import com.sikey.wa04.business.domain.entity.message.MessageId;
import com.sikey.wa04.business.domain.entity.message.MessageReceivedLog;

import java.util.List;

/**
 * Message adapter.
 */
public interface MessageAdapter {

    /**
     * 存消息
     *
     * @param message 消息
     */
    void save(Message message);


    /**
     * 查询消息
     *
     * @param messageId 消息id
     * @return 消息
     */
    Message find(MessageId messageId);

    /**
     * 未读消息数量
     *
     * @param receiverId    接收人
     * @param chatSessionId 会话ID {@link ChatSessionId}
     * @return 未读消息数量
     */
    Integer unreadCount(UserId receiverId, ChatSessionId chatSessionId);


    /**
     * 查询未读消息
     *
     * @param receiverId    接收人
     * @param chatSessionId 会话ID {@link ChatSessionId}
     * @return 未读消息
     */
    List<Message> findUnreadMessages(UserId receiverId, ChatSessionId chatSessionId);

    /**
     * 查询未读消息ackId
     *
     * @param receiverId    接收者
     * @param chatSessionId 会话id
     * @return
     */
    List<Long> findUnreadMessagesAckId(UserId receiverId, ChatSessionId chatSessionId);

    /**
     * 查询未读消息
     *
     * @param receiverId    接收人
     * @param chatSessionId 会话ID {@link ChatSessionId}
     * @param pageNumber    页码
     * @param pageSize      每页数量
     * @return 未读消息
     */
    List<Message> findUnreadMessages(UserId receiverId, ChatSessionId chatSessionId, int pageNumber, int pageSize);

    /**
     * 查询消息读取记录
     *
     * @param messageId 消息ID
     * @return 消息读取记录
     */
    List<MessageReceivedLog> findReceivedLogs(MessageId messageId);

    /**
     * 标记为已读
     *
     * @param receivedLog 消息接收记录
     */
    void markAsRead(MessageReceivedLog receivedLog);

    /**
     * 标记为已读
     *
     * @param ackIdList 消息接收记录集合
     * @return
     */
    void markAsRead(List<Long> ackIdList);
}
