"""
================================================================================
Strategy **D053** — ``s053``
================================================================================
Wednesday + SPY below SMA50 + VIX between 16 and 26.

**Exit / structure:** hold **7** sessions, trade kind ``vtc``, params ``(30, 0.23, 9.0)``.
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": "D053", "theme": "weekday", "title": 'Wednesday bear call mid-week chop'}

HOLD_SESSIONS = 7
TRADE_KIND = "vtc"
TRADE_PARAMS = (30, 0.23, 9.0)


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) != 2:
        return False
    s50 = row.get("sma_50")
    if s50 is None or pd.isna(s50) or float(row["close"]) >= float(s50):
        return False
    vx = ctx.vix(i)
    if not math.isfinite(vx) or vx < 16.0 or vx > 26.0:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
