from __future__ import annotations

from datetime import datetime, timezone

import pytest

from src.market_data.acquisition.adapters.dzengi.websocket import (
    DzengiWebSocketQuoteAdapter,
)
from src.market_data.acquisition.exceptions import QuoteValueError


def test_adapter_maps_document_to_quote() -> None:
    received_at = datetime(2026, 7, 13, tzinfo=timezone.utc)
    result = DzengiWebSocketQuoteAdapter().map_message(
        {
            "Payload": {
                "symbolName": "BTC/USD",
                "bids": [["10", "1"]],
                "asks": [["12", "1"]],
                "timestamp": 1000,
            }
        },
        received_at=received_at,
    )
    assert str(result.last_price) == "11"
    assert result.received_at is received_at


def test_adapter_preserves_layer_error() -> None:
    with pytest.raises(QuoteValueError):
        DzengiWebSocketQuoteAdapter().map_message(
            {"symbol": "BTC/USD", "bid": "12", "ask": "11"}
        )
