"""US-003 (PRD 5.20): build_key incorporeaza rar_env."""

from __future__ import annotations

from app.idempotency import build_key, canonicalize_row


def _canon():
    raw = {
        "vin": "WVWZZZ1JZXW000001", "nr_inmatriculare": "B 123 ABC",
        "data_prestatie": "2026-01-10", "odometru_final": "123456.0",
        "prestatii": [{"cod_prestatie": "OE-1"}],
    }
    canon = canonicalize_row(raw)
    canon["prestatii"] = raw["prestatii"]
    return canon


def test_key_difera_intre_test_si_prod():
    canon = _canon()
    assert build_key(1, canon, "test") != build_key(1, canon, "prod")


def test_key_stabil_pe_env():
    canon = _canon()
    assert build_key(1, canon, "prod") == build_key(1, canon, "prod")
    # None si 1 colapseaza la aceeasi cheie (account_or_default), pe acelasi env
    assert build_key(None, canon, "test") == build_key(1, canon, "test")
