# app/src/market_data/acquisition/handlers/quotes_handler.py

from __future__ import annotations

from datetime import datetime, timezone

from src.market_data.acquisition.adapters.dzengi.mapper import (
    map_dzengi_ticker_to_quote,
)
from src.market_data.acquisition.adapters.dzengi.parser import parse_quote
from src.market_data.acquisition.models.quote import Quote
from src.market_data.acquisition.validation.schema import (
    validate_quote_schema,
)
from src.market_data.acquisition.validation.values import (
    validate_quote_values,
)


# Обработчик документа Quotes Feed формата Dzengi ticker/24hr.
class DzengiQuoteDocumentHandler:
    def handle_quote_document(
        self,
        document: object,
    ) -> Quote:
        validated_document = validate_quote_schema(document)

        response = parse_quote(validated_document)

        validate_quote_values(response)

        return map_dzengi_ticker_to_quote(
            response,
            received_at=datetime.now(timezone.utc),
        )
