from abc import ABC, abstractmethod
from typing import Union


class MessageWrapper():
    """ Abstract class to define methods that must be overwritten by children """

    @abstractmethod
    def create_topic(self, topic: str) -> bool:
        return True

    @abstractmethod
    def delete_topic(self, topic: str) -> bool:
        return True

    @abstractmethod
    def subscribe(self, topic: str) -> bool:
        return True

    @abstractmethod
    def unsubscribe(self, topic: str, topic_link: Union[str, bytes, None] = None, *args, **kwargs) -> bool:
        return True

    @abstractmethod
    def publish(self, topic: str, message: Union[str, dict], subject: str = None, *args, **kwargs):
        return ""

    @classmethod
    def get(cls, message_type='sns', **kwargs):

        from importlib import import_module
        try:
            ret_cls = import_module(f'messaging.topic_providers.{message_type}')
            return ret_cls.MessageWrapper(**kwargs)
        except Exception as e:
            return cls()
