package ru.ulstu.user.repository;

import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import ru.ulstu.user.model.User;

import java.util.Date;
import java.util.List;

public interface UserRepository extends JpaRepository<User, Integer> {
    User findOneByActivationKey(String activationKey);

    List<User> findAllByActivatedIsFalseAndActivationDateBefore(Date date);

    User findOneByResetKey(String resetKey);

    List<User> findAllByResetKeyNotNullAndResetDateBefore(Date date);

    User findOneByEmailIgnoreCase(String email);

    User findOneByLoginIgnoreCase(String login);

    @EntityGraph(attributePaths = "roles")
    User findOneWithRolesById(int id);

    @EntityGraph(attributePaths = "roles")
    User findOneWithRolesByLogin(String login);
}
