"""
================================================================================
Strategy **D090** — ``s090``
================================================================================
``close > 1.06*sma_200`` + VIX<20.

**Exit / structure:** hold **10** sessions, trade kind ``put``, params ``(37, -0.24)``.
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": "D090", "theme": "sma_distance", "title": 'Far above SMA200 short put'}

HOLD_SESSIONS = 10
TRADE_KIND = "put"
TRADE_PARAMS = (37, -0.24)


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