'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var logger = require('../utils/logger.js');

class ReportDataStore {
    redisClient;
    prefix;
    constructor(redisClient, prefix = 'dprReportStoreUser:') {
        this.redisClient = redisClient;
        redisClient.on('error', (error) => {
            logger.default.error(error, `Redis error`);
        });
        this.prefix = prefix;
    }
    async ensureConnected() {
        if (!this.redisClient.isOpen) {
            await this.redisClient.connect();
        }
    }
    async setUserConfig(userId, config) {
        await this.ensureConnected();
        await this.redisClient.set(`${this.prefix}${userId}`, JSON.stringify(config));
    }
    async getUserConfig(userId) {
        await this.ensureConnected();
        const userConfig = await this.redisClient.get(`${this.prefix}${userId}`);
        return userConfig ? JSON.parse(String(userConfig)) : this.setBaseplate(userId);
    }
    async setBaseplate(userId) {
        logger.default.info(`Initialising new DPR user config in store. prefix: ${this.prefix}`);
        const userConfig = { ...baseplateStore };
        await this.setUserConfig(userId, userConfig);
        return { ...baseplateStore };
    }
}
const baseplateStore = {
    requestedReports: [],
    recentlyViewedReports: [],
    bookmarks: [],
    downloadPermissions: [],
    defaultFilters: [],
};

exports.ReportDataStore = ReportDataStore;
exports.default = ReportDataStore;
//# sourceMappingURL=reportDataStore.js.map
