package com.bizzan.bitrade.dao;

import com.bizzan.bitrade.entity.ExperienceGiftProductCoin;
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.transaction.annotation.Transactional;

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

public interface ExperienceGiftProductCoinRepository extends JpaRepository<ExperienceGiftProductCoin, Long> {

    Optional<ExperienceGiftProductCoin> findByProductIdAndCoinSymbol(Long productId, String coinSymbol);

    List<ExperienceGiftProductCoin> findByProductId(Long productId);

    @Transactional
    @Modifying(clearAutomatically = true, flushAutomatically = true)
    @Query("DELETE FROM ExperienceGiftProductCoin c WHERE c.productId = :productId")
    void deleteByProductId(@Param("productId") Long productId);
}
