"""
================================================================================
Strategy **D076** — ``s076``
================================================================================
``close > SMA50`` and ``iv40-iv10 > 0.02``.

**Exit / structure:** hold **8** sessions, trade kind ``vtc``, params ``(31, 0.21, 8.0)``.
Signal logic is implemented only in this module (no imports from sibling strategies).
================================================================================
"""

from __future__ import annotations

import math

import pandas as pd

from RenTech.core.options_data_loader import OptionChain
from RenTech.strategy_stack.diverse_theta_strategies_v1.context import ResearchContext

META = {"sid": "D076", "theme": "call_spread_proxy", "title": 'Strong tape + contango IV bear call'}

HOLD_SESSIONS = 8
TRADE_KIND = "vtc"
TRADE_PARAMS = (31, 0.21, 8.0)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    s50 = row.get("sma_50")
    if s50 is None or pd.isna(s50) or float(row["close"]) <= float(s50):
        return False
    a = ctx.iv_atm_dte(i, 40)
    b = ctx.iv_atm_dte(i, 10)
    if a is None or b is None or a - b <= 0.02:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
