"""Resolve the effective per-track gate policy: registry gate_spec overrides layered on the GatePolicy
defaults at ONE point (no `.get(..., CONSTANT)` scattered across the gate functions). The gate evaluators
take the ResolvedPolicy — the single place defaults and per-track overrides combine."""
from __future__ import annotations

from dataclasses import dataclass
from typing import Any

from fxhnt.application.gate_policy import GatePolicy


@dataclass(frozen=True, slots=True)
class ResolvedPolicy:
    min_forward_days: int
    recon_tolerance_frac: float
    recon_min_band: float
    recon_min_corr: float
    max_gap_days: int
    min_days: int
    min_total_return: float
    min_sharpe: float


def resolve_policy(policy: GatePolicy, gate_spec: dict[str, Any]) -> ResolvedPolicy:
    return ResolvedPolicy(
        min_forward_days=int(gate_spec.get("min_forward_days", policy.min_forward_days)),
        recon_tolerance_frac=float(gate_spec.get("recon_tolerance_frac", policy.recon_tolerance_frac)),
        recon_min_band=float(gate_spec.get("recon_min_band", policy.recon_min_band)),
        recon_min_corr=float(gate_spec.get("recon_min_corr", policy.recon_min_corr)),
        max_gap_days=int(gate_spec.get("max_gap_days", policy.max_gap_days)),
        min_days=int(gate_spec.get("min_days", policy.min_days)),
        min_total_return=float(gate_spec.get("min_total_return", policy.min_total_return)),
        min_sharpe=float(gate_spec.get("min_sharpe", policy.min_sharpe)),
    )
