package app.mealsmadeeasy.api.recipe.comment;

import app.mealsmadeeasy.api.recipe.Recipe;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface RecipeCommentRepository extends JpaRepository<RecipeComment, Integer> {
    void deleteAllByRecipe(Recipe recipe);
    Slice<RecipeComment> findAllByRecipe(Recipe recipe, Pageable pageable);

    @Query("SELECT count(rc) FROM RecipeComment rc WHERE rc.recipe.owner.username = ?1 AND rc.recipe.slug = ?2")
    int countByUsernameAndSlug(String username, String slug);
}
