"""Silver normalizers: raw bronze arrays -> canonical BarRecords (epoch-second ts)."""
from __future__ import annotations

import numpy as np


def test_normalize_futures_builds_adjusted_bars_with_epoch_second_ts() -> None:
    from fxhnt.adapters.warehouse.silver_futures import normalize_futures
    days = np.array([0, 1, 2], dtype=np.int64)        # epoch-days
    inst = np.array([10, 10, 20], dtype=np.int64)     # roll on day 2
    close = np.array([100.0, 102.0, 50.0])
    high = np.array([101.0, 103.0, 51.0])
    low = np.array([99.0, 101.0, 49.0])
    bars = normalize_futures("ES", days, inst, close, high, low)
    assert [b.ts for b in bars] == [0, 86_400, 172_800]          # day * 86400
    assert bars[2].close == bars[1].close                        # roll -> flat synthetic
    assert bars[2].high / bars[2].close == 51.0 / 50.0           # range preserved
    assert all(b.symbol == "ES" for b in bars)


def test_normalize_crypto_builds_close_only_bars() -> None:
    from fxhnt.adapters.warehouse.silver_crypto import normalize_crypto
    day = np.array([19_000, 19_001], dtype=np.int64)   # epoch-days
    close = np.array([42000.0, 43000.0])
    bars = normalize_crypto("BTCUSDT", day, close)
    assert [b.ts for b in bars] == [19_000 * 86_400, 19_001 * 86_400]
    # crypto bronze is close-only -> high == low == close (flat bar)
    assert bars[0].high == bars[0].low == bars[0].close == 42000.0
    assert all(b.symbol == "BTCUSDT" for b in bars)
