package pl.polskalokalnie.notification;

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 org.springframework.data.repository.query.Param;

public interface NotificationRepository extends JpaRepository<Notification, Long> {

    List<Notification> findTop100ByUserEmailIgnoreCaseOrderByCreatedAtDesc(String userEmail);

    long countByUserEmailIgnoreCaseAndReadFalse(String userEmail);

    boolean existsByUserEmailIgnoreCaseAndDedupeKey(String userEmail, String dedupeKey);

    @Modifying
    @Query("update Notification n set n.read = true where lower(n.userEmail) = lower(:email) and n.read = false")
    int markAllRead(@Param("email") String email);
}
