package com.alterdekim.hearthhack.repository;

import com.alterdekim.hearthhack.entity.DeckContent;
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;

public interface DeckContentRepository extends JpaRepository<DeckContent, Long> {

    @Query(value = "SELECT new DeckContent(d.id, d.userId, d.deckId, d.assetId, d.isPremium) FROM DeckContent d WHERE d.userId = :userId AND d.deckId = :deckId")
    List<DeckContent> findCardsByDeckId(@Param("userId") Long userId, @Param("deckId") Long deckId);

    @Transactional
    @Modifying
    @Query(value = "DELETE FROM DeckContent d WHERE d.userId = :userId AND d.deckId = :deckId")
    void clearDeck(@Param("userId") Long userId, @Param("deckId") Long deckId);
}
