package com.izouma.jmrh.repo;

import com.izouma.jmrh.domain.Comment;
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.annotation.Nonnull;
import javax.transaction.Transactional;
import java.util.List;

public interface CommentRepo extends JpaRepository<Comment, Long>, JpaSpecificationExecutor<Comment> {

    @Query("update Comment c set c.del = true where c.id = ?1")
    @Transactional
    @Modifying
    void deleteById(@Nonnull Long id);

    List<Comment> findByPostIdIn(Iterable<Long> postIds);

    @Query("select distinct c.postId from Comment c where c.userId = ?1")
    List<Long> findUserReplyPostId(Long userId);

    Comment findFirstByPostId(Long postId);
}