"use strict";function deepMerge(e,t){const r={...e};for(const a of Object.keys(t))t[a]&&"object"==typeof t[a]&&!Array.isArray(t[a])?r[a]=deepMerge(e[a]||{},t[a]):r[a]=t[a];return r}Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const db_1=require("@b/db"),query_1=require("@b/utils/query"),cache_1=require("@b/utils/cache");exports.metadata={summary:"Update Trading admin settings",operationId:"updateTradingAdminSettings",tags:["Admin","Trading"],requestBody:{required:!0,content:{"application/json":{schema:{type:"object"}}}},responses:(0,query_1.updateRecordResponses)("Settings"),requiresAuth:!0,permission:"access.trading.settings"};exports.default=async e=>{const{body:t}=e,[r,a]=await db_1.models.settings.findOrCreate({where:{key:"trading_pro"},defaults:{key:"trading_pro",value:JSON.stringify(t)}});if(!a){let e={};try{e=JSON.parse(r.value||"{}")}catch(t){e={}}const a=deepMerge(e,t);r.value=JSON.stringify(a);await r.save()}t.chartProvider&&await db_1.models.settings.upsert({key:"trading_pro_chart_provider",value:t.chartProvider});const s=cache_1.CacheManager.getInstance();await s.clearCache();return{success:!0,settings:JSON.parse(r.value)}};