package cz.muni.fi.pa165.soccermanager.repository;

import cz.muni.fi.pa165.soccermanager.entity.User;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface UserRepository extends JpaRepository<User, Long> {

  @Query("SELECT u FROM Users u WHERE u.nickName = :nickname")
  Optional<User> findByNickname(String nickname);

  @Query("SELECT " +
          "CASE " +
            "WHEN COUNT( u ) > 0  THEN true " +
          "ELSE " +
            "false " +
          "END " +
        "FROM Users u WHERE u.nickName = :nickname"
        )
  Boolean nickNameExists(String nickname);
}
