package com.cameleer.server.core.search;

/**
 * Aggregate execution statistics within a time window, with comparison to the
 * equivalent previous period (shifted back 24 h) and a "today" total.
 */
public record ExecutionStats(
        long totalCount,
        long failedCount,
        long avgDurationMs,
        long p99LatencyMs,
        long activeCount,
        long totalToday,
        long prevTotalCount,
        long prevFailedCount,
        long prevAvgDurationMs,
        long prevP99LatencyMs,
        double slaCompliance) {

    /** Constructor without SLA compliance (backward-compatible, sets to -1). */
    public ExecutionStats(long totalCount, long failedCount, long avgDurationMs,
                          long p99LatencyMs, long activeCount, long totalToday,
                          long prevTotalCount, long prevFailedCount,
                          long prevAvgDurationMs, long prevP99LatencyMs) {
        this(totalCount, failedCount, avgDurationMs, p99LatencyMs, activeCount,
                totalToday, prevTotalCount, prevFailedCount, prevAvgDurationMs,
                prevP99LatencyMs, -1.0);
    }

    /** Return a copy with the given SLA compliance value. */
    public ExecutionStats withSlaCompliance(double slaCompliance) {
        return new ExecutionStats(totalCount, failedCount, avgDurationMs, p99LatencyMs,
                activeCount, totalToday, prevTotalCount, prevFailedCount,
                prevAvgDurationMs, prevP99LatencyMs, slaCompliance);
    }
}
