"""Real-time quote endpoints (in-memory cache)."""

from __future__ import annotations

from typing import Any, Dict

from sd_api.client.base import BaseClient
from sd_api.models.quote import Quote, QuoteSnapshot


class RealtimeMixin:
    """Endpoints under /api/quote-live and /api/quotes-live."""

    def __init__(self, base: BaseClient) -> None:
        self._base = base

    def live(self, symbol: str) -> Quote:
        """GET /api/quote-live?symbol=... — single symbol real-time quote from memory cache."""
        symbol = symbol.upper().strip()
        data = self._base.get("/api/quote-live", params={"symbol": symbol})
        return Quote.from_api(data)

    def live_all(self) -> QuoteSnapshot:
        """GET /api/quotes-live — full market real-time snapshot from memory cache."""
        data = self._base.get("/api/quotes-live")
        return QuoteSnapshot.from_api(data)

    def latest(self, symbol: str) -> Quote:
        """GET /api/quote?symbol=... — single symbol latest quote from DB."""
        symbol = symbol.upper().strip()
        data = self._base.get("/api/quote", params={"symbol": symbol})
        return Quote.from_api(data)

    def latest_all(self) -> QuoteSnapshot:
        """GET /api/quotes — full market latest quotes from DB."""
        data = self._base.get("/api/quotes")
        return QuoteSnapshot.from_api(data)
