package com.alterdekim.game.repository;

import com.alterdekim.game.entity.PhoneMessage;
import com.alterdekim.game.entity.Postcard;
import jakarta.transaction.Transactional;
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;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface PostcardRepository extends JpaRepository<Postcard, Long> {
    Optional<Postcard> findById(Long id);

    List<Postcard> findAll();

    @Query(value = "SELECT p FROM Postcard p WHERE p.receiverId = :user_id")
    List<Postcard> findByReceiverId(@Param("user_id") Integer userId);

    @Transactional
    @Modifying
    @Query("UPDATE Postcard p SET p.isNew = false WHERE p.id = :mid")
    void markAsRead(@Param("mid") Long messageId);
}