package com.example.demo.notice;

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;

public interface NoticeRepository extends JpaRepository<Notice, Long> {

    @Query("SELECT n FROM Notice n WHERE n.shopId = :shopId AND n.status = :status " +
            "AND (n.startsAt IS NULL OR n.startsAt <= CURRENT_TIMESTAMP) AND (n.endsAt IS NULL OR n.endsAt >= CURRENT_TIMESTAMP) " +
            "ORDER BY n.pinned DESC, n.createdAt DESC")
    List<Notice> findActiveNotices(@Param("shopId") Long shopId, @Param("status") NoticeStatus status);
}


