"use strict";

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

/**
 * Default configuration for BullishHaramiCross pattern.
 */
const DEFAULT_BULLISH_HARAMI_CROSS_CONFIG = exports.DEFAULT_BULLISH_HARAMI_CROSS_CONFIG = {
  ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG
};
class BullishHaramiCross extends _CandlestickFinder.default {
  constructor(config) {
    const finalConfig = {
      ...DEFAULT_BULLISH_HARAMI_CROSS_CONFIG,
      ...config
    };
    super(finalConfig);
    this.requiredCount = 2;
    this.name = 'BullishHaramiCross';
  }
  logic(data) {
    // Previous day (older) - index 0 - should be a long bearish candle
    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 - should be a doji
    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(prevOpen, prevHigh, prevLow, prevClose) || !this.validateOHLC(currOpen, currHigh, currLow, currClose)) {
      return false;
    }

    // Previous day should be a bearish candle
    let isPrevBearish = prevClose < prevOpen;
    let prevBodySize = Math.abs(prevOpen - prevClose);
    let prevRange = prevHigh - prevLow;

    // Ensure the previous candle has a reasonable body size
    // The body should be at least 50% of the total range (more strict requirement)
    let isPrevSignificant = prevRange > 0 && prevBodySize / prevRange >= 0.5;

    // Current day should be a doji (open ≈ close)
    // Note: approximateEqual uses scale for price comparison precision
    let isCurrDoji = this.approximateEqual(currOpen, currClose);

    // Containment: Current doji should be completely contained within previous candle's body
    // For a bearish previous candle: prevClose < prevOpen
    // So the body range is from prevClose (bottom) to prevOpen (top)
    let bodyTop = prevOpen; // For bearish candle, open is higher
    let bodyBottom = prevClose; // For bearish candle, close is lower

    // Current candle (including shadows) should be contained within previous body
    let hasContainment = currHigh <= bodyTop && currLow >= bodyBottom && currOpen >= bodyBottom && currOpen <= bodyTop && currClose >= bodyBottom && currClose <= bodyTop;
    return isPrevBearish && isPrevSignificant && isCurrDoji && hasContainment;
  }
}
exports.default = BullishHaramiCross;
function bullishharamicross(data, config = DEFAULT_BULLISH_HARAMI_CROSS_CONFIG) {
  return new BullishHaramiCross(config).hasPattern(data);
}
//# sourceMappingURL=BullishHaramiCross.js.map