"""Phase-1 paper-forward gate. Pure function: given a ForwardSummary and the strategy's gate_spec, return a
verdict. It only reports — it never acts. WAIT until enough forward days; then GO if forward return and
Sharpe clear the spec; otherwise NO_GO (edge did not show up out-of-sample-in-time)."""
from __future__ import annotations

from fxhnt.application.forward_models import ForwardSummary, GateVerdict


def evaluate_gate(summary: ForwardSummary, gate_spec: dict) -> GateVerdict:
    min_days = int(gate_spec.get("min_days", 20))
    min_ret = float(gate_spec.get("min_total_return", 0.0))
    min_sharpe = float(gate_spec.get("min_sharpe", 0.0))

    if summary.days < min_days:
        return GateVerdict("WAIT", f"{summary.days}/{min_days} forward days")
    if summary.total_return <= min_ret:
        return GateVerdict("NO_GO", f"forward return {summary.total_return_pct:.2f}% <= floor")
    if summary.sharpe < min_sharpe:
        return GateVerdict("NO_GO", f"forward Sharpe {summary.sharpe:.2f} < {min_sharpe}")
    return GateVerdict("GO", f"{summary.days}d: +{summary.total_return_pct:.2f}%, Sharpe {summary.sharpe:.2f}")
