"use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const db_1=require("@b/db"),query_1=require("@b/utils/query");exports.metadata={summary:"Fetch Missing Currencies",operationId:"fetchMissingCurrencies",tags:["Admin","Settings","Exchange"],description:"Fetches all active markets, extracts unique currencies, compares with active currencies in the database, and returns the missing ones with their IDs.",requiresAuth:!0,responses:{200:{description:"Missing currencies fetched successfully",content:{"application/json":{schema:{type:"object",properties:{missingCurrencies:{type:"array",items:{type:"object",properties:{id:{type:"string"},currency:{type:"string"}}}}}}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Currencies"),500:query_1.serverErrorResponse},permission:"view.spot.currency",logModule:"ADMIN_FIN",logTitle:"Fetch Missing Currencies"};exports.default=async e=>{const{ctx:r}=e;try{null==r||r.step("Fetching active markets");const e=await db_1.models.exchangeMarket.findAll({attributes:["currency","pair"],where:{status:!0}}),s=new Set;e.forEach(e=>{const{currency:r,pair:t}=e;s.add(r);s.add(t)});const t=Array.from(s),i=await db_1.models.exchangeCurrency.findAll({attributes:["id","currency","status"]}),n=i.filter(e=>e.status).map(e=>e.currency),c=t.filter(e=>!n.includes(e)).map(e=>{const r=i.find(r=>r.currency===e);return r&&r.id?{id:r.id,currency:e}:null}).filter(Boolean);null==r||r.success("Missing currencies fetched successfully");return c}catch(e){return{status:500,body:query_1.serverErrorResponse}}};