"""Roaring Kitty (Keith Gill)-style scoring.

Gill's GME thesis combined deep value with an asymmetric catalyst: a
beaten-down but viable business carrying heavy short interest, so that any
improvement could force a squeeze. This scorer blends value cheapness,
short-squeeze fuel (short % of float, days to cover), and turning momentum.
"""
from __future__ import annotations

from ..data import StockData
from ..scoring import (Signal, StrategyResult, combine, higher_better,
                       lower_better, verdict_from)


def evaluate(sd: StockData) -> StrategyResult:
    short_pct = sd.get("shortPercentOfFloat")     # 0..1 fraction
    short_ratio = sd.get("shortRatio")            # days to cover
    pb = sd.get("priceToBook")
    ps = sd.get("priceToSalesTrailing12Months")

    # Turning momentum: recent 1-month up, but still down over the year
    # (a bounce off a beaten-down base — the classic setup).
    ret_1m = sd.returns(21)
    ret_1y = sd.returns(252)

    # Squeeze fuel: high short interest AND high days-to-cover.
    signals = [
        Signal("ShortFloat%", short_pct, higher_better(short_pct, 0.05, 0.30), 0.28,
               "short-squeeze fuel"),
        Signal("DaysToCover", short_ratio, higher_better(short_ratio, 2, 8), 0.20),
        Signal("P/B", pb, lower_better(pb, 0.5, 4.0), 0.12, "value base"),
        Signal("P/S", ps, lower_better(ps, 0.4, 5.0), 0.10),
        Signal("Mom_1M", ret_1m, higher_better(ret_1m, -0.05, 0.20), 0.18,
               "turning catalyst"),
        Signal("Beaten_1Y", ret_1y, lower_better(ret_1y, -0.5, 0.3), 0.12,
               "still cheap vs a year ago"),
    ]
    score = combine(signals)
    return StrategyResult("Roaring Kitty", score, signals, verdict_from(score))
