package com.example.dateplanner.repositories;

import com.example.dateplanner.models.entities.GalleryPost;
import org.springframework.data.r2dbc.repository.Query;
import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.UUID;

public interface GalleryPostRepository extends R2dbcRepository<GalleryPost, UUID> {

    Flux<GalleryPost> findByIsPublishedTrueOrderByPublishedAtDesc();

    Mono<GalleryPost> findFirstByIsPublishedTrueOrderByPublishedAtDesc();

    @Query("SELECT * FROM gallery_posts ORDER BY published_at DESC NULLS LAST, created_at DESC LIMIT :limit OFFSET :offset")
    Flux<GalleryPost> findRecentPublished(int limit, int offset);

    @Query("SELECT COUNT(*) FROM gallery_posts WHERE is_published = true")
    Mono<Long> countPublished();
}
