package com.alterdekim.hearthhack.repository;

import com.alterdekim.hearthhack.entity.CardBack;
import com.alterdekim.hearthhack.entity.HeroXP;
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 CardBackRepository extends JpaRepository<CardBack, Long> {
    List<CardBack> findByUserId(Long userId);

    @Query(value = "SELECT TRUE FROM CardBack c WHERE c.userId = :userId AND c.backId = :cardBack")
    Boolean isUserHasCardBack(@Param("userId") Long userId, @Param("cardBack") Integer cardBack);

    @Query(value = "SELECT c FROM CardBack c WHERE c.userId = :userId AND c.backId = :cardBack")
    Optional<CardBack> findByUserIdAndBackId(@Param("userId") Long userId, @Param("cardBack") Integer cardBack);
}
