import { assertValidGLTFCorpusManifest, createGLTFCorpusReport } from "./AssetCorpus.js";
export function createAssetCompatibilityReport(manifest, options = {}) {
    const validated = assertValidGLTFCorpusManifest(manifest);
    const corpusReport = createGLTFCorpusReport(validated, options.generatedAt ?? new Date().toISOString());
    const blenderExportFixturesPresent = options.blenderExportFixturesPresent ?? options.blenderExportValidation !== undefined;
    const externalResults = indexExternalLoaderResults(options.externalLoaderResults ?? []);
    const blenderExportResults = indexBlenderExportResults(options.blenderExportResults ?? []);
    const assets = corpusReport.assets.map((asset) => createCompatibilityAsset(asset, blenderExportFixturesPresent, externalResults, blenderExportResults));
    return {
        schemaVersion: "asset-compatibility-report",
        generatedAt: corpusReport.generatedAt,
        sourceManifest: corpusReport.sourceManifest,
        fixtureStatus: {
            blenderExportFixtures: blenderExportFixturesPresent ? "present" : "missing"
        },
        ...(options.blenderExportValidation ? { blenderExportValidation: options.blenderExportValidation } : {}),
        summary: {
            assetCount: assets.length,
            aura3d: summarize(assets, "aura3d"),
            threejs: summarize(assets, "threejs"),
            babylonjs: summarize(assets, "babylonjs"),
            blenderExport: summarize(assets, "blender-export")
        },
        assets
    };
}
function createCompatibilityAsset(asset, blenderExportFixturesPresent, externalResults, blenderExportResults) {
    return {
        id: asset.id,
        name: asset.name,
        format: asset.format,
        tags: asset.tags,
        sourceUri: asset.sourceUri,
        sourceRevision: asset.sourceRevision,
        sourceSha256: asset.sourceSha256,
        importSettings: asset.importSettings,
        loaders: [
            {
                loader: "aura3d",
                status: asset.expectedStatus === "expected-fail" ? "expected-fail" : asset.expectedStatus,
                diagnostics: asset.diagnostics
            },
            externalResults.get(externalResultKey(asset.id, "threejs")) ?? externalLoaderScaffold("threejs", asset),
            externalResults.get(externalResultKey(asset.id, "babylonjs")) ?? externalLoaderScaffold("babylonjs", asset),
            blenderExportResults.get(asset.id) ?? blenderExportScaffold(asset, blenderExportFixturesPresent)
        ]
    };
}
function indexExternalLoaderResults(results) {
    const indexed = new Map();
    for (const result of results) {
        indexed.set(externalResultKey(result.assetId, result.loader), {
            loader: result.loader,
            status: result.status,
            diagnostics: result.diagnostics
        });
    }
    return indexed;
}
function indexBlenderExportResults(results) {
    const indexed = new Map();
    for (const result of results) {
        indexed.set(result.assetId, {
            loader: result.loader,
            status: result.status,
            diagnostics: result.diagnostics
        });
    }
    return indexed;
}
function externalResultKey(assetId, loader) {
    return `${assetId}:${loader}`;
}
function externalLoaderScaffold(loader, asset) {
    return {
        loader,
        status: "not-run",
        diagnostics: [
            diagnostic(`ASSET_${loader.toUpperCase()}_LOADER_NOT_RUN`, "External loader compatibility has not been executed in this bounded slice.", `Run ${asset.id} through a pinned ${loader} GLTFLoader version and record pass, warn, or expected-fail evidence before claiming ${loader} parity.`)
        ]
    };
}
function blenderExportScaffold(asset, fixturesPresent) {
    if (fixturesPresent) {
        return {
            loader: "blender-export",
            status: "not-run",
            diagnostics: [
                diagnostic("ASSET_BLENDER_EXPORT_VALIDATION_PENDING", "Blender export fixtures were detected, but no export validation runner is wired in this slice.", `Run ${asset.id} or the matching fixture through the Blender exporter validation command and record the exported glTF diagnostics.`)
            ]
        };
    }
    return {
        loader: "blender-export",
        status: "not-run",
        diagnostics: [
            diagnostic("ASSET_BLENDER_EXPORT_FIXTURES_MISSING", "No Blender-export fixtures are present in the asset test corpus.", "Add checked-in exported glTF/GLB fixtures before marking Blender-export validation complete.")
        ]
    };
}
function summarize(assets, loader) {
    const counts = {
        pass: 0,
        warn: 0,
        "expected-fail": 0,
        "not-run": 0
    };
    for (const asset of assets) {
        const result = asset.loaders.find((entry) => entry.loader === loader);
        counts[result?.status ?? "not-run"] += 1;
    }
    return counts;
}
function diagnostic(code, message, nextAction) {
    return {
        code,
        severity: "info",
        message,
        nextAction
    };
}
//# sourceMappingURL=AssetCompatibility.js.map