package com.cameleer.server.core.agent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Instant;

public class AgentEventService {

    private static final Logger log = LoggerFactory.getLogger(AgentEventService.class);

    private final AgentEventRepository repository;

    public AgentEventService(AgentEventRepository repository) {
        this.repository = repository;
    }

    public void recordEvent(String instanceId, String applicationId, String environment, String eventType, String detail) {
        log.debug("Recording agent event: instance={}, app={}, env={}, type={}", instanceId, applicationId, environment, eventType);
        repository.insert(instanceId, applicationId, environment, eventType, detail);
    }

    public AgentEventPage queryEventPage(String applicationId, String instanceId, String environment,
                                          Instant from, Instant to, String cursor, int limit) {
        return repository.queryPage(applicationId, instanceId, environment, from, to, cursor, limit);
    }
}
