# app/tests/unit/trading/strategies/test_scalp_quote.py

from __future__ import annotations

import inspect
from datetime import datetime, timezone
from decimal import Decimal

import src.trading.strategies.scalp as module
from src.market_data.acquisition.models.quote import Quote
from src.trading.strategies.scalp import ScalpStrategy


def _quote(
    *,
    last: str = "100.5",
    bid: str = "100.0",
    ask: str = "101.0",
) -> Quote:
    return Quote(
        symbol="BTC/USD_LEVERAGE",
        last_price=Decimal(last),
        bid_price=Decimal(bid),
        ask_price=Decimal(ask),
        exchange_timestamp=None,
        received_at=datetime.now(timezone.utc),
        source="dzengi",
    )


def test_scalp_uses_midpoint_from_quote() -> None:
    result = ScalpStrategy()._analysis_price(_quote())

    assert result == 100.5


def test_scalp_quote_snapshot_is_json_compatible_projection() -> None:
    result = ScalpStrategy()._quote_snapshot(_quote())

    assert result == {
        "symbol": "BTC/USD_LEVERAGE",
        "last_price": 100.5,
        "bid_price": 100.0,
        "ask_price": 101.0,
        "source": "dzengi",
    }


def test_scalp_has_no_legacy_market_snapshot_call() -> None:
    source = inspect.getsource(module.ScalpStrategy)

    assert "get_quote(" in source
