/**
 * WebSocket 보조지표를 차트 형식으로 변환
 * (투자분석 CandlestickTestPage와 동일)
 */
export function mapWsIndicatorsToChartFormat(ws: Record<string, unknown>): Record<string, unknown> {
  const out: Record<string, unknown> = {};
  const w = ws as Record<string, unknown>;

  if (ws.macd != null) out.macdLine = ws.macd;
  if (w.macdLine != null) out.macdLine = w.macdLine;
  if (w.macd_line != null) out.macdLine = w.macd_line;
  if (ws.macd_signal != null) {
    out.signalLine = ws.macd_signal;
    out.macdSignal = ws.macd_signal;
  }
  if (w.macdSignal != null) {
    out.signalLine = w.macdSignal;
    out.macdSignal = w.macdSignal;
  }
  if (ws.macd_histogram != null) out.macdHistogram = ws.macd_histogram;
  if (w.macdHistogram != null) out.macdHistogram = w.macdHistogram;
  if (w.histogram != null) out.macdHistogram = w.histogram;
  if (ws.rsi_14 != null) out.rsi = ws.rsi_14;
  if (w.rsi != null) out.rsi = w.rsi;
  if (ws.stoch_k != null) {
    out.stochasticK = ws.stoch_k;
    out.stochK = ws.stoch_k;
  }
  if (ws.stoch_d != null) out.stochasticD = ws.stoch_d;
  if (w.stochasticK != null) out.stochasticK = w.stochasticK;
  if (w.stochasticD != null) out.stochasticD = w.stochasticD;

  if (ws.stoch_slow_k != null) out.stochasticSlowK = ws.stoch_slow_k;
  if (ws.stoch_slow_d != null) out.stochasticSlowD = ws.stoch_slow_d;
  if (w.stochasticSlowK != null) out.stochasticSlowK = w.stochasticSlowK;
  if (w.stochasticSlowD != null) out.stochasticSlowD = w.stochasticSlowD;

  if (ws.bb_upper != null) out.bbUpper = ws.bb_upper;
  if (ws.bb_middle != null) out.bbMiddle = ws.bb_middle;
  if (ws.bb_lower != null) out.bbLower = ws.bb_lower;
  if (ws.ema_9 != null) out.ema9 = ws.ema_9;
  if (ws.ema_21 != null) out.ema21 = ws.ema_21;
  if (ws.adx != null) out.adx = ws.adx;
  if (ws.plus_di != null) out.plusDI = ws.plus_di;
  if (ws.minus_di != null) out.minusDI = ws.minus_di;
  if (w.plusDi != null) out.plusDI = w.plusDi;
  if (w.minusDi != null) out.minusDI = w.minusDi;

  if (ws.ma_5 != null) out.ma5 = ws.ma_5;
  if (ws.ma_10 != null) out.ma10 = ws.ma_10;
  if (ws.ma_20 != null) out.ma20 = ws.ma_20;
  if (ws.ma_60 != null) out.ma60 = ws.ma_60;
  if (ws.ma_120 != null) out.ma120 = ws.ma_120;

  if (ws.ichimoku_tenkan != null) out.ichimokuTenkan = ws.ichimoku_tenkan;
  if (ws.ichimoku_kijun != null) out.ichimokuKijun = ws.ichimoku_kijun;
  if (ws.ichimoku_senkou_a != null) out.ichimokuSenkouA = ws.ichimoku_senkou_a;
  if (ws.ichimoku_senkou_b != null) out.ichimokuSenkouB = ws.ichimoku_senkou_b;
  if (ws.ichimoku_chikou != null) out.ichimokuChikou = ws.ichimoku_chikou;

  if (ws.cci != null) {
    out.cci = ws.cci;
    out.cci13 = ws.cci;
  }
  if (w.cci13 != null) {
    out.cci13 = w.cci13;
    if (out.cci == null) out.cci = w.cci13;
  }
  if (ws.cci_signal != null) out.cciSignal = ws.cci_signal;
  if (w.cciSignal != null) out.cciSignal = w.cciSignal;
  if (ws.obv != null) out.obv = ws.obv;
  if (ws.obv_signal != null) out.obvSignal = ws.obv_signal;
  if (w.obvSignal != null) out.obvSignal = w.obvSignal;
  if (ws.williams_r != null) out.williamsR = ws.williams_r;
  if (ws.trix != null) out.trix = ws.trix;
  if (ws.trix_signal != null) out.trixSignal = ws.trix_signal;
  if (ws.bwi != null) out.bwi = ws.bwi;
  if (ws.volume_osc != null) out.volumeOsc = ws.volume_osc;
  if (ws.vr != null) out.vr = ws.vr;
  if (ws.vr2 != null) out.vr2 = ws.vr2;
  if (ws.new_psy != null) {
    out.newPsy = ws.new_psy;
    out.newPsychological = ws.new_psy;
  }
  if (ws.invest_psy != null) {
    out.investPsy = ws.invest_psy;
    out.investPsychological = ws.invest_psy;
  }
  if (w.newPsychological != null) out.newPsychological = w.newPsychological;
  if (w.investPsychological != null) out.investPsychological = w.investPsychological;
  if (ws.disparity_ultra_short != null) out.disparityUltraShort = ws.disparity_ultra_short;
  if (ws.disparity_short != null) out.disparityShort = ws.disparity_short;
  if (ws.disparity_mid != null) out.disparityMid = ws.disparity_mid;
  if (out.stochasticK != null && out.stochK == null) out.stochK = out.stochasticK;
  if (out.newPsy != null && out.newPsychological == null) out.newPsychological = out.newPsy;
  if (out.newPsychological != null && out.newPsy == null) out.newPsy = out.newPsychological;
  if (out.investPsy != null && out.investPsychological == null) out.investPsychological = out.investPsy;
  if (out.investPsychological != null && out.investPsy == null) out.investPsy = out.investPsychological;

  return out;
}
