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

from fxhnt.application.forward_models import CAT_IMMATURE, CAT_PASS, ForwardSummary, GateVerdict
from fxhnt.application.gate_policy_resolve import ResolvedPolicy


def evaluate_gate(summary: ForwardSummary, policy: ResolvedPolicy) -> GateVerdict:
    min_days = policy.min_days
    min_ret = policy.min_total_return
    min_sharpe = policy.min_sharpe

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