package com.kospo.talk.repository;

import com.kospo.talk.model.TalkRead;
import com.kospo.talk.model.TalkReadId;
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;

public interface TalkReadRepository extends JpaRepository<TalkRead, TalkReadId> {
    @Modifying
    @Transactional
    @Query(value="update talk_read set read_yn = true where talk_id = :talkId and sabun = :sabun", nativeQuery = true)
    void updateTalkReadYn(@Param("talkId") String talkId, @Param("sabun") String sabun);

    @Transactional
    @Modifying
    @Query(value="insert into talk_read\n" +
            "select :talkId, sabun, true, ins_date from talk_read where talk_id = :pTalkId", nativeQuery = true)
    int dataCopyReadForce(@Param("pTalkId") String pTalkId, @Param("talkId") String talkId);

    @Transactional
    @Modifying
    @Query(value="insert into talk_read\n" +
            "select :talkId, sabun, read_yn, ins_date from talk_read where talk_id = :pTalkId", nativeQuery = true)
    int dataCopyReadOri(@Param("pTalkId") String pTalkId, @Param("talkId") String talkId);
}