"use strict";function applyAdjustment(e,t){return 0===t?e:Math.round(e*(1+t/100))}function calculateCumulativeAdjustments(e){var t;const r=[...e].sort((e,t)=>e.minutes-t.minutes),n={RISE_FALL:0,HIGHER_LOWER:0,TOUCH_NO_TOUCH:0,CALL_PUT:0,TURBO:0},o=new Map;for(const e of r){const r=e.orderTypeOverrides||{};for(const e of ORDER_TYPES){const o=(null===(t=r[e])||void 0===t?void 0:t.profitAdjustment)||0;0!==o&&(n[e]+=o)}o.set(e.id,{...n})}return o}function convertDurationToResponse(e,t,r){const{orderTypes:n}=t,o=applyAdjustment(n.RISE_FALL.profitPercentage,r.RISE_FALL),a=applyAdjustment(n.HIGHER_LOWER.profitPercentage,r.HIGHER_LOWER),i=applyAdjustment(n.TOUCH_NO_TOUCH.profitPercentage,r.TOUCH_NO_TOUCH),s=applyAdjustment(n.CALL_PUT.profitPercentage,r.CALL_PUT),u=applyAdjustment(n.TURBO.profitPercentage,r.TURBO);return{id:e.id,duration:e.minutes,profitPercentageRiseFall:o,profitPercentageHigherLower:a,profitPercentageTouchNoTouch:i,profitPercentageCallPut:s,profitPercentageTurbo:u,profitPercentage:o,status:e.enabled}}Object.defineProperty(exports,"__esModule",{value:!0});exports.metadata=void 0;const binary_settings_cache_1=require("@b/utils/binary-settings-cache"),query_1=require("@b/utils/query");exports.metadata={summary:"List Available Binary Durations",operationId:"listBinaryDurations",tags:["Exchange","Binary"],description:"Retrieves a list of available durations for binary options with calculated profit percentages.",logModule:"EXCHANGE",logTitle:"Get Binary Durations",responses:{200:{description:"A list of binary durations with calculated profit percentages",content:{"application/json":{schema:{type:"array",items:{type:"object",properties:{id:{type:"string"},duration:{type:"number"},profitPercentageRiseFall:{type:"number"},profitPercentageHigherLower:{type:"number"},profitPercentageTouchNoTouch:{type:"number"},profitPercentageCallPut:{type:"number"},profitPercentageTurbo:{type:"number"},status:{type:"boolean"}}}}}}},401:query_1.unauthorizedResponse,404:(0,query_1.notFoundMetadataResponse)("Binary Duration"),500:query_1.serverErrorResponse}};const ORDER_TYPES=["RISE_FALL","HIGHER_LOWER","TOUCH_NO_TOUCH","CALL_PUT","TURBO"];exports.default=async e=>{const{ctx:t}=e;null==t||t.step("Fetching binary settings");const r=await(0,binary_settings_cache_1.getBinarySettings)(),n=calculateCumulativeAdjustments(r.durations),o=r.durations.filter(e=>e.enabled).sort((e,t)=>e.minutes-t.minutes).map(e=>{const t=n.get(e.id)||{RISE_FALL:0,HIGHER_LOWER:0,TOUCH_NO_TOUCH:0,CALL_PUT:0,TURBO:0};return convertDurationToResponse(e,r,t)});null==t||t.success(`Retrieved ${o.length} binary durations from settings`);return o};