from __future__ import annotations

import pytest

from src.market_data.acquisition.adapters.dzengi.models import DzengiWebSocketQuoteResponse
from src.market_data.acquisition.exceptions import QuoteValueError
from src.market_data.acquisition.validation.values import (
    validate_dzengi_websocket_quote_values,
)


def _response(**overrides: object) -> DzengiWebSocketQuoteResponse:
    values = {
        "symbol": "BTC/USD",
        "bid_price": "10",
        "ask_price": "11",
        "timestamp": 1000,
    }
    values.update(overrides)
    return DzengiWebSocketQuoteResponse(**values)  # type: ignore[arg-type]


def test_accepts_valid_values_and_missing_timestamp() -> None:
    validate_dzengi_websocket_quote_values(_response())
    validate_dzengi_websocket_quote_values(_response(timestamp=None))


@pytest.mark.parametrize(
    "overrides",
    [
        {"symbol": " "},
        {"bid_price": "0"},
        {"ask_price": "-1"},
        {"bid_price": "NaN"},
        {"bid_price": "12", "ask_price": "11"},
        {"timestamp": 0},
    ],
)
def test_rejects_invalid_values(overrides: dict[str, object]) -> None:
    with pytest.raises(QuoteValueError):
        validate_dzengi_websocket_quote_values(_response(**overrides))
