/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { bufferToString } from "@fluid-internal/client-utils";
import { createSingleBlobSummary } from "@fluidframework/shared-object-base/internal";
/**
 * The storage key for the blob in the summary containing schema data
 */
const detachedFieldIndexBlobKey = "DetachedFieldIndexBlob";
/**
 * Provides methods for summarizing and loading a tree index.
 */
export class DetachedFieldIndexSummarizer {
    constructor(detachedFieldIndex) {
        this.detachedFieldIndex = detachedFieldIndex;
        this.key = "DetachedFieldIndex";
    }
    getAttachSummary(stringify, fullTree, trackState, telemetryContext) {
        const data = this.detachedFieldIndex.encode();
        return 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 = bufferToString(detachedFieldIndexBuffer, "utf8");
            const parsed = parse(treeBufferString);
            this.detachedFieldIndex.loadData(parsed);
        }
    }
}
//# sourceMappingURL=detachedFieldIndexSummarizer.js.map