"""
================================================================================
Strategy **D081** — ``s081``
================================================================================
``day_of_month<=14`` + SPY>SMA200 + VIX<19.

**Exit / structure:** hold **9** sessions, trade kind ``put``, params ``(34, -0.2)``.
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": "D081", "theme": "month_half", "title": 'First half month short put'}

HOLD_SESSIONS = 9
TRADE_KIND = "put"
TRADE_PARAMS = (34, -0.2)


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