"use strict";async function getBinarySettings(){return exports.binarySettingsCache.get()}function invalidateBinarySettingsCache(){exports.binarySettingsCache.invalidate()}Object.defineProperty(exports,"__esModule",{value:!0});exports.BinarySettingsCache=exports.binarySettingsCache=void 0;exports.getBinarySettings=getBinarySettings;exports.invalidateBinarySettingsCache=invalidateBinarySettingsCache;const db_1=require("@b/db"),utils_1=require("@b/api/admin/finance/binary/settings/utils");class BinarySettingsCache{constructor(t=6e4){this.cache=null;this.lastFetch=0;this.fetchPromise=null;this.TTL=t}async get(){if(this.cache&&Date.now()-this.lastFetch<this.TTL)return this.cache;if(this.fetchPromise)return this.fetchPromise;this.fetchPromise=this.fetchFromDB();try{const t=await this.fetchPromise;this.cache=t;this.lastFetch=Date.now();return t}finally{this.fetchPromise=null}}async fetchFromDB(){try{const t=await db_1.models.settings.findOne({where:{key:"binarySettings"}});if(null==t?void 0:t.value)try{const e=JSON.parse(t.value);return(0,utils_1.mergeWithDefaults)(e)}catch(t){console.error("Failed to parse binary settings:",t);return utils_1.DEFAULT_BINARY_SETTINGS}return utils_1.DEFAULT_BINARY_SETTINGS}catch(t){console.error("Failed to fetch binary settings from DB:",t);return utils_1.DEFAULT_BINARY_SETTINGS}}invalidate(){this.cache=null;this.lastFetch=0}async refresh(){this.invalidate();return this.get()}isValid(){return null!==this.cache&&Date.now()-this.lastFetch<this.TTL}getAge(){return this.cache?Date.now()-this.lastFetch:1/0}}exports.BinarySettingsCache=BinarySettingsCache;exports.binarySettingsCache=new BinarySettingsCache;