"""Reference-only implementation for the BTC Trap Playbook.

This file is intentionally simple and is not production trading software.
"""

from __future__ import annotations

from typing import Any, Dict, List


DOWNSIDE_MAGNET_ZONE = [58000, 60000]


def evaluate_btc_trap(price: float, volume_trend: str, channel_status: str) -> Dict[str, Any]:
    if volume_trend == "fading" and channel_status == "rejected":
        return {
            "trap_risk": "elevated",
            "downside_magnet_zone": DOWNSIDE_MAGNET_ZONE,
            "confidence": 0.72,
            "reason": "Participation is fading while structure is being rejected.",
        }

    if volume_trend in {"mixed", "fading"} or channel_status in {"neutral", "rejected"}:
        return {
            "trap_risk": "moderate",
            "downside_magnet_zone": DOWNSIDE_MAGNET_ZONE,
            "confidence": 0.63,
            "reason": "The rebound lacks enough structural quality to be upgraded confidently.",
        }

    return {
        "trap_risk": "contained",
        "downside_magnet_zone": DOWNSIDE_MAGNET_ZONE,
        "confidence": 0.58,
        "reason": "Trap risk is present but not dominant under current participation and structure.",
    }


def batch_evaluate(rows: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
    outputs: List[Dict[str, Any]] = []
    for row in rows:
        outputs.append(
            evaluate_btc_trap(
                price=float(row["price"]),
                volume_trend=str(row["volume_trend"]),
                channel_status=str(row["channel_status"]),
            )
        )
    return outputs
