package de.szut.casino.deposit;

import de.szut.casino.user.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Service;

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

@Service
public interface TransactionRepository extends JpaRepository<TransactionEntity, Long> {
    @Query("SELECT t FROM TransactionEntity t WHERE t.sessionId = ?1")
    Optional<TransactionEntity> findOneBySessionID(String sessionId);

    @Query("SELECT t FROM TransactionEntity t WHERE t.user = ?1")
    List<TransactionEntity> findAllByUserId(UserEntity id);

    @Query("SELECT t FROM TransactionEntity t WHERE t.user = ?1 ORDER BY t.createdAt DESC LIMIT ?2 OFFSET ?3")
    List<TransactionEntity> findByUserIdWithLimit(UserEntity userEntity, Integer limit, Integer offset);

    @Query("SELECT COUNT(t) > ?2 + ?3 FROM TransactionEntity t WHERE t.user = ?1")
    Boolean hasMore(UserEntity userEntity, Integer limit, Integer offset);
}
