import logger from '../utils/logger.js';

class ReportDataStore {
    redisClient;
    prefix;
    constructor(redisClient, prefix = 'dprReportStoreUser:') {
        this.redisClient = redisClient;
        redisClient.on('error', (error) => {
            logger.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.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: [],
};

export { ReportDataStore, ReportDataStore as default };
//# sourceMappingURL=reportDataStore.js.map
