from logging import Logger

from interactor.route.loyalty.search_customer_info.dto import SearchCustomerInfoRequest
from model.config import Config
from model.repository import PosRepositoryModel
from model.services import LoyaltyServiceModel
from validation_util import (
    check_if_business_day_is_opened,
    check_if_operator_is_logged,
    validate_api_key,
    check_if_order_is_in_progress,
)

from typing import Dict


class SearchCustomerInfoInteractor(object):
    def __init__(
        self,
        logger,             # type: Logger
        config,             # type: Config
        pos_repository,     # type: PosRepositoryModel
        loyalty_service,    # type: LoyaltyServiceModel
    ):
        # type: (...) -> None

        self.logger = logger
        self.config = config
        self.pos_repository = pos_repository
        self.loyalty_service = loyalty_service

    def execute(
        self,
        request     # type: SearchCustomerInfoRequest
    ):
        # type: (...) -> Dict

        pos_id = validate_api_key(
            request=request,
            secure_api_key_list=self.config.api_key_mapping,
        )

        model = self.pos_repository.get_model(pos_id)
        pos_ot = self.pos_repository.get_pos_ot(
            model=model,
        )
        response = self.loyalty_service.get_customer_info(
            pos_ot=pos_ot,
            customer_id=request.customer_id,
        )

        return response
