package studycave.studycaverestservice.model.simpleTest;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

public interface SimpleTestRepository extends JpaRepository<SimpleTest, Long> {
    List<SimpleTest> findAll();

    Optional<SimpleTest> findByGroupIdAndTitleLike(Integer groupId, String title);

    @Query("select t from SimpleTest t where (:permission is null or t.permission = :permission) and "
            + "(:owner is null or t.idOwner = :owner) and t.groupId is null")
    List<SimpleTest> findByGroupIdNullAndOptionalPermissionAndOptionalOwner(@Param("permission") String permission,
                                                                            @Param("owner") Long owner);
}
