from abc import ABCMeta
from logging import Logger

from typing import Optional

from dialogmanager import DialogManager
from messagebus import MessageBus

cache_last_receipt = {}
settings_mb_context = None


class Cache(object):
    __metaclass__ = ABCMeta

    def __init__(
        self,
        message_bus,        # type: MessageBus
        dialog_manager,     # type: DialogManager
        logger,             # type: Logger
    ):
        # type: (...) -> None

        self.message_bus = message_bus
        self.dialog_manager = dialog_manager
        self.logger = logger

    @staticmethod
    def set_last_receipt(
        receipt_data,       # type: str
        eft_processor,      # type: str
    ):
        # type: (...) -> None

        if eft_processor in ['', None]:
            return

        global cache_last_receipt

        cache_last_receipt[str(eft_processor.upper())] = receipt_data

    @staticmethod
    def get_last_receipt(
        eft_processor,      # type: str
    ):
        # type: (...) -> Optional[str]

        if eft_processor in ['', None]:
            return

        global cache_last_receipt

        return cache_last_receipt.get(str(eft_processor.upper()), None)

