package de.szut.casino.user;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public interface UserRepository extends JpaRepository<UserEntity, Long> {
    Optional<UserEntity> findByUsername(String username);

    Optional<UserEntity> findByEmail(String email);

    Optional<UserEntity> findByProviderId(String providerId);

    boolean existsByUsername(String username);

    boolean existsByEmail(String email);

    @Query("SELECT u FROM UserEntity u WHERE u.verificationToken = ?1")
    Optional<UserEntity> findOneByVerificationToken(String token);

    @Query("SELECT u FROM UserEntity u WHERE u.username = ?1 OR u.email = ?1")
    Optional<UserEntity> findOneByUsernameOrEmail(String usernameOrEmail);

    @Query("SELECT u FROM UserEntity u WHERE u.passwordResetToken = ?1")
    Optional<UserEntity> findOneByPasswordResetToken(String token);
}
