"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.DEFAULT_BEARISH_MARUBOZU_CONFIG = void 0;
exports.bearishmarubozu = bearishmarubozu;
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 BearishMarubozu pattern.
 * Includes body tolerance thresholds for determining shadow significance.
 */

/**
 * Default configuration for BearishMarubozu pattern.
 */
const DEFAULT_BEARISH_MARUBOZU_CONFIG = exports.DEFAULT_BEARISH_MARUBOZU_CONFIG = {
  ..._CandlestickFinder.DEFAULT_CANDLESTICK_CONFIG,
  bodyTolerancePercent: 0.015,
  bodyToleranceMinimum: 0.00015
};
class BearishMarubozu extends _CandlestickFinder.default {
  bodyTolerancePercent;
  bodyToleranceMinimum;
  constructor(config) {
    const finalConfig = {
      ...DEFAULT_BEARISH_MARUBOZU_CONFIG,
      ...config
    };
    super(finalConfig);
    this.name = 'BearishMarubozu';
    this.requiredCount = 1;

    // Apply configuration with defaults
    this.bodyTolerancePercent = finalConfig.bodyTolerancePercent;
    this.bodyToleranceMinimum = finalConfig.bodyToleranceMinimum;
  }
  logic(data) {
    let daysOpen = data.open[0];
    let daysClose = data.close[0];
    let daysHigh = data.high[0];
    let daysLow = data.low[0];

    // Validate OHLC data
    if (!this.validateOHLC(daysOpen, daysHigh, daysLow, daysClose)) {
      return false;
    }

    // Bearish Marubozu: open > close, open = high, close = low (no shadows)
    let isBearish = daysOpen > daysClose;

    // For Marubozu, we need strict equality for open=high and close=low
    // Allow small tolerance for rounding errors but reject significant shadows
    let bodySize = Math.abs(daysOpen - daysClose);
    // Use direct threshold calculation instead of utility function
    let maxTolerance = Math.max(bodySize * this.bodyTolerancePercent, this.bodyToleranceMinimum);
    let upperShadow = Math.abs(daysHigh - daysOpen);
    let lowerShadow = Math.abs(daysLow - daysClose);
    let isOpenEqualsHigh = upperShadow <= maxTolerance;
    let isCloseEqualsLow = lowerShadow <= maxTolerance;
    let isBearishMarubozu = isBearish && isOpenEqualsHigh && isCloseEqualsLow;
    return isBearishMarubozu;
  }
}

/**
 * Detects Bearish Marubozu candlestick pattern in the provided stock data.
 *
 * A Bearish Marubozu is a long bearish candlestick with no upper or lower shadows,
 * indicating strong selling pressure throughout the trading session. The opening price
 * equals the high and the closing price equals the low.
 *
 * @param data - Stock data containing OHLC values
 * @param config - Configuration object for pattern detection
 * @param config.scale - Scale parameter for approximateEqual function precision (default: 0.001)
 * @param config.bodyTolerancePercent - Body tolerance as percentage of body size (default: 0.015 = 1.5%)
 * @param config.bodyToleranceMinimum - Minimum body tolerance absolute value (default: 0.00015)
 * @returns True if Bearish Marubozu pattern is detected, false otherwise
 *
 * @example
 * ```typescript
 * // Using default configuration
 * const hasBearishMarubozuPattern = bearishmarubozu(stockData);
 *
 * // Using custom configuration
 * const hasBearishMarubozuPattern = bearishmarubozu(stockData, {
 *   scale: 0.002,
 *   bodyTolerancePercent: 0.02,
 *   bodyToleranceMinimum: 0.0002
 * });
 *
 * // Backward compatibility with scale parameter
 * const hasBearishMarubozuPattern = bearishmarubozu(stockData, { scale: 0.002 });
 * ```
 */
exports.default = BearishMarubozu;
function bearishmarubozu(data, config = DEFAULT_BEARISH_MARUBOZU_CONFIG) {
  return new BearishMarubozu(config).hasPattern(data);
}
//# sourceMappingURL=BearishMarubozu.js.map