package org.jebot.repository.jebot;

import org.jebot.models.jebot.BotAccountBook;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;

@Component
public interface BotAccountBookRepository extends JpaRepository<BotAccountBook, Long> {
    BotAccountBook findByBelongIdAndType(Long belongId, String type);

    @Modifying
    @Transactional
    @Query("UPDATE bot_account_book SET paymentBalance =:paymentBalanceNew WHERE id =:id AND paymentBalance =:paymentBalanceOld")
    void updatePaymentBalanceByIdAndPaymentBalance(double paymentBalanceNew,Long id, double paymentBalanceOld);

    @Modifying
    @Transactional
    @Query("UPDATE bot_account_book SET agentBalance =:agentBalanceNew WHERE id =:id AND agentBalance =:agentBalanceOld")
    void updateAgentBalanceByIdAndAgentBalance(double agentBalanceNew, Long id, double agentBalanceOld);
}
