/**
 * fidelity.ts — Structured import fidelity reporting
 *
 * ## Purpose
 *
 * The fidelity system tracks how faithfully data survives format conversions
 * (especially the lossy ContentPack → WorldProject round-trip). Every import
 * converter produces {@link FidelityEntry} records that are aggregated into a
 * {@link FidelityReport}.
 *
 * ## How to Create Fidelity Entries for a Custom Converter
 *
 * 1. Import {@link FidelityEntry} and {@link FidelityDomain} from this module.
 * 2. If your converter introduces a new data category, add it to the
 *    {@link FidelityDomain} union type (e.g. `'my-domain'`).
 * 3. In your converter, create entries with the appropriate {@link FidelityLevel}:
 *    - `'lossless'` — data was preserved exactly.
 *    - `'approximated'` — data was reconstructed with heuristics (e.g. inferred
 *      grid positions, default values substituted).
 *    - `'dropped'` — data could not be recovered and was lost.
 * 4. Set `severity` to `'info'` for routine observations, `'warning'` for data
 *    the user should review, or `'error'` for data loss that may break the project.
 * 5. Return your entries array alongside your converted data. The import pipeline
 *    collects all entries and calls {@link buildFidelityReport} to produce the
 *    aggregate {@link FidelityReport}.
 *
 * @module fidelity
 */
export function summarizeFidelity(entries) {
    let lossless = 0;
    let approximated = 0;
    let dropped = 0;
    const byDomain = {};
    for (const e of entries) {
        if (e.level === 'lossless')
            lossless++;
        else if (e.level === 'approximated')
            approximated++;
        else
            dropped++;
        let ds = byDomain[e.domain];
        if (!ds) {
            ds = { total: 0, lossless: 0, approximated: 0, dropped: 0 };
            byDomain[e.domain] = ds;
        }
        ds.total++;
        ds[e.level]++;
    }
    const total = entries.length;
    return {
        total,
        lossless,
        approximated,
        dropped,
        losslessPercent: total === 0 ? 100 : Math.round((lossless / total) * 100),
        byDomain,
    };
}
export function buildFidelityReport(entries) {
    return { entries, summary: summarizeFidelity(entries) };
}
//# sourceMappingURL=fidelity.js.map