"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "SimpleDocumentStore", {
    enumerable: true,
    get: function() {
        return SimpleDocumentStore;
    }
});
const _env = require("@llamaindex/env");
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
const _constants = require("../constants.js");
const _SimpleKVStore = require("../kvStore/SimpleKVStore.js");
const _types = require("../kvStore/types.js");
const _KVDocumentStore = require("./KVDocumentStore.js");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
class SimpleDocumentStore extends _KVDocumentStore.KVDocumentStore {
    kvStore;
    constructor(kvStore, namespace){
        kvStore = kvStore || new _SimpleKVStore.SimpleKVStore();
        namespace = namespace || _constants.DEFAULT_NAMESPACE;
        super(kvStore, namespace);
        this.kvStore = kvStore;
    }
    static async fromPersistDir(persistDir = _constants.DEFAULT_PERSIST_DIR, namespace) {
        const persistPath = _env.path.join(persistDir, _constants.DEFAULT_DOC_STORE_PERSIST_FILENAME);
        return await SimpleDocumentStore.fromPersistPath(persistPath, namespace);
    }
    static async fromPersistPath(persistPath, namespace) {
        const simpleKVStore = await _SimpleKVStore.SimpleKVStore.fromPersistPath(persistPath);
        return new SimpleDocumentStore(simpleKVStore, namespace);
    }
    async persist(persistPath = _env.path.join(_constants.DEFAULT_PERSIST_DIR, _constants.DEFAULT_DOC_STORE_PERSIST_FILENAME)) {
        if (_lodash.default.isObject(this.kvStore) && this.kvStore instanceof _types.BaseInMemoryKVStore) {
            await this.kvStore.persist(persistPath);
        }
    }
    static fromDict(saveDict, namespace) {
        const simpleKVStore = _SimpleKVStore.SimpleKVStore.fromDict(saveDict);
        return new SimpleDocumentStore(simpleKVStore, namespace);
    }
    toDict() {
        if (_lodash.default.isObject(this.kvStore) && this.kvStore instanceof _SimpleKVStore.SimpleKVStore) {
            return this.kvStore.toDict();
        }
        // If the kvstore is not a SimpleKVStore, you might want to throw an error or return a default value.
        throw new Error("KVStore is not a SimpleKVStore");
    }
}
