package dev.ksan.etfoglasiserver.repository;

import dev.ksan.etfoglasiserver.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface UserRepo extends JpaRepository<User, UUID> {

    @Query("SELECT u FROM User u WHERE u.email = :email")
    Optional<User> findByEmail(String email);


    @Query("SELECT u FROM User u JOIN u.subjectSet s WHERE s.id = :subjectId")
    List<User> findUsersBySubjectId(@Param("subjectId") UUID id);
}
