package com.izouma.zhirongip.repo;

import com.izouma.zhirongip.domain.Information;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface InformationRepo extends JpaRepository<Information, Long>, JpaSpecificationExecutor<Information> {
    @Query("update Information t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    /*
    批量已读
     */
    @Query("update Information t set t.isRead = true where t.receiveUserId = ?1")
    @Modifying
    @Transactional
    void batchRead(Long receiveUserId);

    /*
    批量删除
     */
    @Query("update Information t set t.del = true where t.receiveUserId = ?1")
    @Modifying
    @Transactional
    void batchSoftDelete(Long receiveUserId);

    /*
    未读数量
     */
    int countByReceiveUserIdAndIsReadFalse(Long receiveUserId);

    /*
   批量删除留言消息
    */
    @Query("update Information t set t.del = true where t.messageId = ?1")
    @Modifying
    @Transactional
    void batchSoftDeleteByMessageId(Long messageId);
}