package com.alterdekim.hearthhack.repository;

import com.alterdekim.hearthhack.entity.User;
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 org.springframework.transaction.annotation.Transactional;

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
    User findByUsername(String username);

    @Transactional
    @Modifying
    @Query(value = "UPDATE User u SET u.defaultCardBack = :cardBackId WHERE u.id = :userId")
    void updateCardBackOfUser(@Param("userId") Long userId, @Param("cardBackId") Long cardBackId);


    @Transactional
    @Modifying
    @Query(value = "UPDATE User u SET u.goldBalance = :goldCount WHERE u.id = :userId")
    void updateGoldOfUser(@Param("userId") Long userId, @Param("goldCount") Integer goldCount);
}