package com.ccwangluo.ccim.database;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.ccwangluo.ccim.modle.MessageContent;

import java.util.List;

@Dao
public interface MessageDao {
    @Query("SELECT * FROM messagecontent")
    List<MessageContent> getAll();

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(MessageContent messageContent);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insertList(List<MessageContent> messageContents);

    @Query("SELECT * FROM messagecontent where msgId = :msgId")
    MessageContent getMsgById(Long msgId);

    @Query("SELECT * FROM messagecontent where reciveUserId =:userId order by msgId desc limit 1")
    MessageContent getLastMsgById(long userId);

    @Query("SELECT count(*) FROM messagecontent where senderUserId = :userId and reciveUserId=:myUserId and msgId > :msgId")
    Long selectOfflineCount(Long userId, Long myUserId, Long msgId);
}
