package com.cameleer.server.core.alerting;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;

/**
 * Fires one {@code AlertInstance} per matching {@code agent_events} row in the
 * lookback window. Per-subject fire mode (see
 * {@link AgentLifecycleEventType}) — each {@code (agent, eventType, timestamp)}
 * tuple is independently ackable, driven by a canonical
 * {@code _subjectFingerprint} in the instance context and the partial unique
 * index on {@code alert_instances}.
 */
public record AgentLifecycleCondition(
        AlertScope scope,
        List<AgentLifecycleEventType> eventTypes,
        int withinSeconds
) implements AlertCondition {

    public AgentLifecycleCondition {
        if (eventTypes == null || eventTypes.isEmpty()) {
            throw new IllegalArgumentException("eventTypes must not be empty");
        }
        if (withinSeconds < 1) {
            throw new IllegalArgumentException("withinSeconds must be >= 1");
        }
        eventTypes = List.copyOf(eventTypes);
    }

    @Override
    @JsonProperty(value = "kind", access = JsonProperty.Access.READ_ONLY)
    public ConditionKind kind() { return ConditionKind.AGENT_LIFECYCLE; }
}
