package studycave.studycaverestservice.model.simpleSet;

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 SimpleSetRepository extends JpaRepository<SimpleSet, Long> {
    SimpleSet save(SimpleSet set);

    List<SimpleSet> findAll();

    Optional<SimpleSet> findById(Long id);


    @Query("select s from SimpleSet s where (:permission is null or s.permission = :permission) and "
            + "(:owner is null or s.idOwner = :owner) and groupId is null")
    List<SimpleSet> findByOptionalPermissionAndOptionalOwnerAndGroupIdNull(@Param("permission") String permission,
                                                                           @Param("owner") Integer owner);
}
