"""
================================================================================
Strategy **D052** — ``s052``
================================================================================
Tuesday + SPY above SMA200 + VIX below 21.

**Exit / structure:** hold **10** sessions, trade kind ``put``, params ``(36, -0.21)``.
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": "D052", "theme": "weekday", "title": 'Tuesday short OTM put bull tape'}

HOLD_SESSIONS = 10
TRADE_KIND = "put"
TRADE_PARAMS = (36, -0.21)


def wants_entry(i: int, row: pd.Series, ch: OptionChain, spy: float, ctx: ResearchContext) -> bool:
    wd = row.get("weekday")
    if wd is None or pd.isna(wd) or int(wd) != 1:
        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 >= 21.0:
        return False
    if ctx.chain_contracts(i) < 90 or not ch.contracts:
        return False
    _ = spy
    return True
