"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.DetachedFieldIndexSummarizer = void 0;
const shared_object_base_1 = require("@fluidframework/shared-object-base");
const client_utils_1 = require("@fluid-internal/client-utils");
/**
 * The storage key for the blob in the summary containing schema data
 */
const detachedFieldIndexBlobKey = "DetachedFieldIndexBlob";
/**
 * Provides methods for summarizing and loading a tree index.
 */
class DetachedFieldIndexSummarizer {
    constructor(detachedFieldIndex) {
        this.detachedFieldIndex = detachedFieldIndex;
        this.key = "DetachedFieldIndex";
    }
    getAttachSummary(stringify, fullTree, trackState, telemetryContext) {
        const data = this.detachedFieldIndex.encode();
        return (0, shared_object_base_1.createSingleBlobSummary)(detachedFieldIndexBlobKey, stringify(data));
    }
    async summarize(stringify, fullTree, trackState, telemetryContext) {
        return this.getAttachSummary(stringify, fullTree, trackState, telemetryContext);
    }
    getGCData(fullGC) {
        // TODO: Properly implement garbage collection. Right now, garbage collection is performed automatically
        // by the code in SharedObject (from which SharedTreeCore extends). The `runtime.uploadBlob` API delegates
        // to the `BlobManager`, which automatically populates the summary with ISummaryAttachment entries for each
        // blob.
        return {
            gcNodes: {},
        };
    }
    async load(services, parse) {
        if (await services.contains(detachedFieldIndexBlobKey)) {
            const detachedFieldIndexBuffer = await services.readBlob(detachedFieldIndexBlobKey);
            const treeBufferString = (0, client_utils_1.bufferToString)(detachedFieldIndexBuffer, "utf8");
            const parsed = parse(treeBufferString);
            this.detachedFieldIndex.loadData(parsed);
        }
    }
}
exports.DetachedFieldIndexSummarizer = DetachedFieldIndexSummarizer;
//# sourceMappingURL=detachedFieldIndexSummarizer.js.map