package com.wzj.soopin.im.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import com.wzj.soopin.im.domain.SysMessageUser;
import com.wzj.soopin.im.domain.vo.SysMessageUserVo;

/**
 * 消息用户关联Mapper接口
 *
 * @author ruoyi
 */
public interface SysMessageUserMapper extends BaseMapperPlus<SysMessageUser, SysMessageUserVo> {

    /**
     * 更新消息读取状态
     *
     * @param messageId 消息ID
     * @param userId 用户ID
     * @param isRead 是否已读
     * @return 结果
     */
    default int updateReadStatus(Long messageId, Long userId, boolean isRead) {
        LambdaQueryWrapper<SysMessageUser> lqw = Wrappers.lambdaQuery();
        lqw.eq(SysMessageUser::getMessageId, messageId)
            .eq(SysMessageUser::getUserId, userId);
        SysMessageUser messageUser = new SysMessageUser();
        messageUser.setIsRead(isRead);
        return update(messageUser, lqw);
    }
}
