"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DEFAULT_BULLISH_ENGULFING_CONFIG = void 0;
exports.bullishengulfingpattern = bullishengulfingpattern;
exports.default = void 0;
var _CandlestickFinder = _interopRequireWildcard(require("./CandlestickFinder"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
 * Configuration interface for BullishEngulfingPattern.
 * Only requires scale parameter since this pattern uses direct price comparisons.
 */

/**
 * Default configuration for BullishEngulfingPattern.
 */
const DEFAULT_BULLISH_ENGULFING_CONFIG = exports.DEFAULT_BULLISH_ENGULFING_CONFIG = {
  ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG
};
class BullishEngulfingPattern extends _CandlestickFinder.default {
  constructor(config) {
    const finalConfig = {
      ...DEFAULT_BULLISH_ENGULFING_CONFIG,
      ...config
    };
    super(finalConfig);
    this.name = 'BullishEngulfingPattern';
    this.requiredCount = 2;
  }
  logic(data) {
    // Previous day (older) - index 0
    let prevOpen = data.open[0];
    let prevClose = data.close[0];
    let prevHigh = data.high[0];
    let prevLow = data.low[0];

    // Current day (most recent) - index 1
    let currOpen = data.open[1];
    let currClose = data.close[1];
    let currHigh = data.high[1];
    let currLow = data.low[1];

    // Validate OHLC data
    if (!this.validateOHLC(currOpen, currHigh, currLow, currClose) || !this.validateOHLC(prevOpen, prevHigh, prevLow, prevClose)) {
      return false;
    }

    // Previous day should be bearish (red)
    let prevIsBearish = prevClose < prevOpen;

    // Current day should be bullish (green)
    let currIsBullish = currClose > currOpen;

    // Current day should engulf previous day's body:
    // For a bullish engulfing pattern:
    // - Current close should be >= previous open (covers top of previous body)
    // - Current open should be <= previous close (covers bottom of previous body)
    // OR for gap scenarios: current range should exceed previous range
    let normalEngulfing = currClose >= prevOpen && currOpen <= prevClose;

    // For gap up scenarios: if current open > previous close,
    // check if current close still exceeds previous open (the key requirement)
    // AND ensure the current candle is not smaller than the previous candle (prevent reverse engulfment)
    let gapEngulfing = false;
    if (currOpen > prevClose && currClose > prevOpen) {
      // Additional check: current candle should have a meaningful size relative to previous
      let currBodySize = Math.abs(currClose - currOpen);
      let prevBodySize = Math.abs(prevOpen - prevClose);
      // Current body should be at least 50% of previous body size to be considered engulfing
      gapEngulfing = currBodySize >= prevBodySize * 0.5;
    }
    let isEngulfing = normalEngulfing || gapEngulfing;
    let isBullishEngulfing = prevIsBearish && currIsBullish && isEngulfing;
    return isBullishEngulfing;
  }
}
exports.default = BullishEngulfingPattern;
function bullishengulfingpattern(data, config = DEFAULT_BULLISH_ENGULFING_CONFIG) {
  return new BullishEngulfingPattern(config).hasPattern(data);
}
//# sourceMappingURL=BullishEngulfingPattern.js.map