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

from __future__ import annotations

from src.market_data.acquisition.adapters.dzengi.mapper import (
    map_dzengi_exchange_info_to_instruments,
)
from src.market_data.acquisition.adapters.dzengi.parser import (
    parse_exchange_info,
)
from src.market_data.acquisition.models.instrument import Instrument
from src.market_data.acquisition.validation.schema import (
    validate_exchange_info_schema,
)
from src.market_data.acquisition.validation.values import (
    validate_exchange_info_values,
)


# Обработчик документа Instrument Reference Data формата Dzengi exchangeInfo.
class DzengiInstrumentDocumentHandler:
    def handle_instrument_document(
        self,
        document: object,
    ) -> tuple[Instrument, ...]:
        validated_document = validate_exchange_info_schema(document)

        response = parse_exchange_info(validated_document)

        validate_exchange_info_values(response)

        return map_dzengi_exchange_info_to_instruments(response)