"""
================================================================================
Strategy **D057** — ``s057``
================================================================================
Skew diff at (30,-0.20,0.12) above 0.056 + SPY>SMA200 + VIX<24.

**Exit / structure:** hold **8** sessions, trade kind ``rr``, params ``(30, -0.2, 0.12)``.
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": "D057", "theme": "skew", "title": 'Extreme 30d skew short RR'}

HOLD_SESSIONS = 8
TRADE_KIND = "rr"
TRADE_PARAMS = (30, -0.2, 0.12)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    sk = ctx.skew_iv_diff(i, 30, -0.20, 0.12)
    if sk is None or sk <= 0.056:
        return False
    s200 = row.get("sma_200")
    if s200 is None or pd.isna(s200) or float(row["close"]) <= float(s200):
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx >= 24.0:
        return False
    if ctx.chain_contracts(i) < 90 or not ch.contracts:
        return False
    _ = spy
    return True
