package com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository;

import java.time.OffsetDateTime;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.CommentEntity;

public interface CommentRepository extends JpaRepository<CommentEntity, Long> {

    @Query("select e from CommentEntity e where e.fileId = :fileId and e.annotationId = :annotationId " + "and (:includeDeletions = true or e.softDeletedTime is null)")
    List<CommentEntity> findByFileIdAndAnnotationId(String fileId, String annotationId, boolean includeDeletions);


    @Query("select e from CommentEntity e where e.fileId = :fileId and (:includeDeletions = true or e.softDeletedTime is null)")
    List<CommentEntity> findByFileId(String fileId, boolean includeDeletions);


    boolean existsByFileIdAndSoftDeletedTimeIsNull(String fileId);


    @Modifying
    @Query("update CommentEntity c set c.softDeletedTime = :softDeleteTime where c.id = :id")
    int updateSoftDelete(long id, OffsetDateTime softDeleteTime);

}
