"""
================================================================================
Strategy **D097** — ``s097``
================================================================================
``iv30(i)-iv30(i-10) > 0.015`` + VRP at 30d.

**Exit / structure:** hold **5** sessions, trade kind ``ss``, params ``(30,)``.
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": "D097", "theme": "iv_slope_slow", "title": 'Ten-session rise in IV30 short straddle'}

HOLD_SESSIONS = 5
TRADE_KIND = "ss"
TRADE_PARAMS = (30,)


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, 30)
    a10 = ctx.iv_atm_dte(i - 10, 30)
    if a0 is None or a10 is None or a0 - a10 <= 0.015:
        return False
    rv = float(row["rv21"]) if pd.notna(row.get("rv21")) else float("nan")
    if not math.isfinite(rv) or rv <= 0 or a0 <= rv:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
