package de.assecutor.votianlt.repository;

import de.assecutor.votianlt.model.PendingMqttMessage;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

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

@Repository
public interface PendingMqttMessageRepository extends MongoRepository<PendingMqttMessage, ObjectId> {

    /**
     * Find all pending messages ordered by creation time (oldest first)
     */
    List<PendingMqttMessage> findAllByOrderByCreatedAtAsc();

    /**
     * Find messages that haven't been retried for a while (for cleanup)
     */
    List<PendingMqttMessage> findByLastRetryAtBeforeOrLastRetryAtIsNull(LocalDateTime before);

    /**
     * Count pending messages
     */
    long count();

    /**
     * Delete messages older than specified date (for cleanup)
     */
    void deleteByCreatedAtBefore(LocalDateTime before);
}