from typing import Dict, Any

from nreports_api.shared import JSON
from ._PreAccountBuilder import PreAccountBuilder
from nreports.services import PreAccountOrdersRetrieverService


class PreAccountQuickServiceBuilder(PreAccountBuilder):

    def build_data(
        self,
        data_to_build: Dict[str, JSON],
        **kwargs: Any,
    ) -> Dict[str, JSON]:

        pos_id = int(kwargs["posId"])
        order_id = int(kwargs["orderId"])

        self._build_mobile_variables(
            data_to_build=data_to_build,
            **kwargs,
        )

        order_retriever_service = PreAccountOrdersRetrieverService(
            message_bus=self._message_bus,
            user_repository=self.user_repository,
            store_config_repository=self.store_config_repository,
        )
        table = order_retriever_service.get_parsed_table_order_from_quick_service(
            pos_id=pos_id,
            order_id=order_id,
        )

        self._build_header(
            data_to_build=data_to_build,
            table=table,
        )

        self._build_body(
            pos_id=pos_id,
            data_to_build=data_to_build,
            table=table,
        )

        self._build_totals(
            data_to_build=data_to_build,
            table=table,
        )

        self._build_footer(data_to_build=data_to_build)

        return data_to_build
