"""
================================================================================
Strategy **D082** — ``s082``
================================================================================
``day_of_month>=19`` and VIX percentile >0.7.

**Exit / structure:** hold **4** sessions, trade kind ``sl``, params ``(15,)``.
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": "D082", "theme": "month_half", "title": 'Second half month long straddle'}

HOLD_SESSIONS = 4
TRADE_KIND = "sl"
TRADE_PARAMS = (15,)


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) < 19:
        return False
    pr = row.get("vix_pct_rank_252")
    if pr is None or pd.isna(pr) or float(pr) <= 0.7:
        return False
    if ctx.chain_contracts(i) < 80 or not ch.contracts:
        return False
    _ = spy
    return True
