"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get EncryptionUtils () {
        return _encryption.EncryptionUtils;
    },
    get MultiLevelCache () {
        return _cache.MultiLevelCache;
    },
    get storage () {
        return storage;
    }
});
const _utils = require("@vlian/utils");
const _cache = require("./cache");
const _encryption = require("./encryption");
function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
let Storage = class Storage {
    get local() {
        return this._local;
    }
    get session() {
        return this._session;
    }
    get indexedDB() {
        return this._indexedDB;
    }
    /**
     * 获取本地存储缓存
     */ get localCache() {
        return this._localCache;
    }
    /**
     * 获取会话存储缓存
     */ get sessionCache() {
        return this._sessionCache;
    }
    /**
   * 获取单例实例
   * 
   * @returns Singleton 实例
   */ static getInstance() {
        if (!Storage.instance) {
            Storage.instance = new Storage();
        }
        return Storage.instance;
    }
    initialize(options) {
        const local = (0, _utils.createStorage)({
            type: 'local',
            prefix: options?.prefix || 'vlian',
            defaultExpire: options?.defaultExpire || 24 * 60 * 60 * 1000
        });
        const session = (0, _utils.createStorage)({
            type: 'session',
            prefix: options?.prefix || 'vlian',
            defaultExpire: options?.defaultExpire || 24 * 60 * 60 * 1000
        });
        const indexedDB = (0, _utils.createStorage)({
            type: 'indexedDB',
            prefix: options?.prefix || 'vlian',
            defaultExpire: options?.defaultExpire || 24 * 60 * 60 * 1000,
            dbName: options?.tableName
        });
        this._local = local;
        this._session = session;
        this._indexedDB = indexedDB;
        // 初始化缓存
        this.cacheEnabled = options?.cache?.enabled ?? false;
        if (this.cacheEnabled) {
            this._localCache = new _cache.MultiLevelCache(local, {
                defaultTTL: options?.cache?.defaultTTL,
                maxSize: options?.cache?.maxSize
            });
            this._sessionCache = new _cache.MultiLevelCache(session, {
                defaultTTL: options?.cache?.defaultTTL,
                maxSize: options?.cache?.maxSize
            });
        }
    }
    /**
     * 清理过期缓存
     */ async cleanupCache() {
        if (this._localCache) {
            await this._localCache.cleanup();
        }
        if (this._sessionCache) {
            await this._sessionCache.cleanup();
        }
    }
    /**
     * 私有构造函数，防止外部直接实例化
     */ constructor(){
        _define_property(this, "_local", void 0);
        _define_property(this, "_session", void 0);
        _define_property(this, "_indexedDB", void 0);
        _define_property(this, "_localCache", void 0);
        _define_property(this, "_sessionCache", void 0);
        _define_property(this, "cacheEnabled", false);
    // 私有构造函数
    }
};
_define_property(Storage, "instance", null);
const storage = Storage.getInstance();

//# sourceMappingURL=index.js.map