"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DEFAULT_BEARISH_ENGULFING_CONFIG = void 0;
exports.bearishengulfingpattern = bearishengulfingpattern;
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 BearishEngulfingPattern.
 * Only requires scale parameter since this pattern uses direct price comparisons.
 */

/**
 * Default configuration for BearishEngulfingPattern.
 */
const DEFAULT_BEARISH_ENGULFING_CONFIG = exports.DEFAULT_BEARISH_ENGULFING_CONFIG = {
  ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG
};
class BearishEngulfingPattern extends _CandlestickFinder.default {
  constructor(config) {
    const finalConfig = {
      ...DEFAULT_BEARISH_ENGULFING_CONFIG,
      ...config
    };
    super(finalConfig);
    this.name = 'BearishEngulfingPattern';
    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 integrity
    let prevValid = this.validateOHLC(prevOpen, prevHigh, prevLow, prevClose);
    let currValid = this.validateOHLC(currOpen, currHigh, currLow, currClose);
    if (!prevValid || !currValid) {
      return false;
    }

    // Previous day should be bullish (green)
    let prevIsBullish = prevClose > prevOpen;

    // Current day should be bearish (red)
    let currIsBearish = currClose < currOpen;

    // Current day should engulf previous day:
    // - Current open above previous close (gap up or continuation)
    // - Current close below previous open (complete engulfment)
    let isEngulfing = currOpen >= prevClose && currClose <= prevOpen;
    let isBearishEngulfing = prevIsBullish && currIsBearish && isEngulfing;
    return isBearishEngulfing;
  }
}

/**
 * Detects Bearish Engulfing candlestick pattern in the provided stock data.
 *
 * A Bearish Engulfing pattern consists of two candlesticks where a large bearish candle
 * completely engulfs the previous smaller bullish candle. This pattern indicates a potential
 * reversal from bullish to bearish sentiment.
 *
 * @param data - Stock data containing OHLC values for at least 2 periods
 * @param config - Configuration object for pattern detection
 * @param config.scale - Scale parameter for approximateEqual function precision (default: 0.001)
 * @returns True if Bearish Engulfing pattern is detected, false otherwise
 *
 * @example
 * ```typescript
 * // Using default configuration
 * const hasBearishEngulfingPattern = bearishengulfingpattern(stockData);
 *
 * // Using custom configuration
 * const hasBearishEngulfingPattern = bearishengulfingpattern(stockData, {
 *   scale: 0.002
 * });
 *
 * // Backward compatibility with scale parameter
 * const hasBearishEngulfingPattern = bearishengulfingpattern(stockData, { scale: 0.002 });
 * ```
 */
exports.default = BearishEngulfingPattern;
function bearishengulfingpattern(data, config = DEFAULT_BEARISH_ENGULFING_CONFIG) {
  return new BearishEngulfingPattern(config).hasPattern(data);
}
//# sourceMappingURL=BearishEngulfingPattern.js.map