# app/tests/unit/market_data/acquisition/models/test_candle.py

from __future__ import annotations

from dataclasses import FrozenInstanceError
from datetime import datetime, timezone
from decimal import Decimal

import pytest

from src.market_data.acquisition.models.candle import Candle


def _candle() -> Candle:
    return Candle(
        symbol="BTC/USD",
        interval="1m",
        open_time=datetime(2026, 7, 15, 6, 0, tzinfo=timezone.utc),
        open_price=Decimal("100"),
        high_price=Decimal("110"),
        low_price=Decimal("90"),
        close_price=Decimal("105"),
        volume=Decimal("12.5"),
        source="rest_klines:bid",
    )


def test_candle_stores_canonical_values() -> None:
    candle = _candle()

    assert candle.symbol == "BTC/USD"
    assert candle.interval == "1m"
    assert candle.open_time.tzinfo is timezone.utc
    assert candle.open_price == Decimal("100")
    assert candle.high_price == Decimal("110")
    assert candle.low_price == Decimal("90")
    assert candle.close_price == Decimal("105")
    assert candle.volume == Decimal("12.5")
    assert candle.source == "rest_klines:bid"


def test_candle_is_frozen() -> None:
    candle = _candle()

    with pytest.raises(FrozenInstanceError):
        candle.close_price = Decimal("106")  # type: ignore[misc]


def test_candle_uses_slots() -> None:
    candle = _candle()

    assert not hasattr(candle, "__dict__")
