"""
================================================================================
Strategy **D098** — ``s098``
================================================================================
``iv40(i)-iv40(i-10) < -0.012`` + VIX<32.

**Exit / structure:** hold **4** sessions, trade kind ``sl``, params ``(15,)``.
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": "D098", "theme": "iv_slope_slow", "title": 'Ten-session fall in IV40 long straddle'}

HOLD_SESSIONS = 4
TRADE_KIND = "sl"
TRADE_PARAMS = (15,)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    if i < 10:
        return False
    a0 = ctx.iv_atm_dte(i, 40)
    a10 = ctx.iv_atm_dte(i - 10, 40)
    if a0 is None or a10 is None or a0 - a10 >= -0.012:
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx >= 32.0:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
