import PageCacheError from "../../errors/PageCacheError.js";
/**
 * Immutable snapshot of page-cache counters.
 */
export default class PageCacheStats {
    hits;
    misses;
    evictions;
    resident;
    maxResident;
    constructor(init) {
        this.hits = validateCounter(init.hits, "hits");
        this.misses = validateCounter(init.misses, "misses");
        this.evictions = validateCounter(init.evictions, "evictions");
        this.resident = validateCounter(init.resident, "resident");
        this.maxResident = validatePositiveInteger(init.maxResident, "maxResident");
        if (this.resident > this.maxResident) {
            throw new PageCacheError(`PageCacheStats resident=${String(this.resident)} exceeds maxResident=${String(this.maxResident)}`, {
                code: "E_PAGE_CACHE_STATS",
                context: {
                    resident: this.resident,
                    maxResident: this.maxResident,
                },
            });
        }
        Object.freeze(this);
    }
}
function validateCounter(value, label) {
    if (!Number.isInteger(value) || value < 0) {
        throw new PageCacheError(`PageCacheStats ${label} must be a non-negative integer; received ${String(value)}`, {
            code: "E_PAGE_CACHE_STATS",
            context: { label, value },
        });
    }
    return value;
}
function validatePositiveInteger(value, label) {
    if (!Number.isInteger(value) || value <= 0) {
        throw new PageCacheError(`PageCacheStats ${label} must be a positive integer; received ${String(value)}`, {
            code: "E_PAGE_CACHE_STATS",
            context: { label, value },
        });
    }
    return value;
}
