/**
 * LogRingBuffer — Fixed-capacity circular buffer for deployment log entries.
 *
 * Provides O(1) append with automatic eviction of the oldest entry when full.
 * getAll() returns entries in chronological (insertion) order.
 */
const DEFAULT_CAPACITY = 5000;
export class LogRingBuffer {
    capacity;
    buffer;
    writeIndex = 0;
    count = 0;
    constructor(capacity = DEFAULT_CAPACITY) {
        this.capacity = capacity;
        this.buffer = [];
    }
    /** Append a log entry. Evicts the oldest entry when at capacity. */
    push(entry) {
        if (this.count < this.capacity) {
            this.buffer.push(entry);
            this.count++;
        }
        else {
            this.buffer[this.writeIndex] = entry;
        }
        this.writeIndex = (this.writeIndex + 1) % this.capacity;
    }
    /** Return all entries in chronological order. */
    getAll() {
        if (this.count < this.capacity) {
            return this.buffer.slice();
        }
        // Buffer is full and may have wrapped — writeIndex points to the oldest entry
        return [...this.buffer.slice(this.writeIndex), ...this.buffer.slice(0, this.writeIndex)];
    }
    /** Remove all entries and reset the buffer. */
    clear() {
        this.buffer = [];
        this.writeIndex = 0;
        this.count = 0;
    }
    /** Current number of entries in the buffer. */
    get size() {
        return this.count;
    }
}
