package com.cameleer.server.core.agent;

import java.time.Instant;
import java.util.List;

public interface AgentEventRepository {

    void insert(String instanceId, String applicationId, String environment, String eventType, String detail);

    /**
     * Cursor-paginated query ordered by (timestamp DESC, instance_id ASC). The cursor
     * is an opaque base64 string produced by the implementation; pass {@code null} for
     * the first page.
     */
    AgentEventPage queryPage(String applicationId, String instanceId, String environment,
                             Instant from, Instant to, String cursor, int limit);

    /**
     * Inclusive-exclusive window query ordered by (timestamp ASC, instance_id ASC)
     * used by the AGENT_LIFECYCLE alert evaluator. {@code eventTypes} is required
     * and must be non-empty; the implementation filters via {@code event_type IN (...)}.
     * Scope filters ({@code applicationId}, {@code instanceId}) are optional. The
     * returned list is capped at {@code limit} rows.
     */
    List<AgentEventRecord> findInWindow(String environment,
                                        String applicationId,
                                        String instanceId,
                                        List<String> eventTypes,
                                        Instant fromInclusive,
                                        Instant toExclusive,
                                        int limit);
}
