package com.eactive.eai.rms.ext.djb.webhook.repository;


import java.time.LocalDateTime;
import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.eactive.eai.data.jpa.BaseRepository;
import com.eactive.eai.rms.data.EMSDataSource;
import com.eactive.eai.rms.data.entity.onl.djb.webhook.WebhookSendLog;

@Repository
@EMSDataSource
public interface WebhookSendLogRepository extends BaseRepository<WebhookSendLog, Long> {

    // 오라클 CHAR(1) Y/N 기준 조회
    @Query("SELECT l FROM WebhookSendLog l " +
           "WHERE l.success = 'N' AND l.retryCount < :maxRetry")
    List<WebhookSendLog> findFailedLogs(@Param("maxRetry") int maxRetry);

    @Query("SELECT l FROM WebhookSendLog l " +
           "WHERE l.eventType = :eventType " +
           "AND l.createdAt BETWEEN :from AND :to")
    List<WebhookSendLog> findByEventTypeAndPeriod(
            @Param("eventType") String eventType,
            @Param("from") LocalDateTime from,
            @Param("to") LocalDateTime to);
}