# Path: golem/core/responses/responses.py
# class MessageElement:
#     """
#     Base class for message elements.
#     """
#     def to_message(self, fbid):
#         return {"recipient": {"id": fbid}, "message": self.to_response()}
# 
#     def to_response(self):
#         pass
# 
#     def get_response_for(self, platform='fb'):
#         return str(self)  # TODO
# 
#     def set_message_tag(self, tag):
#         self.tag = tag
# 
#     def get_message_tag(self):
#         """
#         See https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags
#         :return: FB message tag
#         """
#         if hasattr(self, "tag"):
#             return self.tag
#         return None
# 
#     def __str__(self):
#         return str(self.__dict__)
# 
#     def __repr__(self):
#         return str(self)
# 
# Path: golem/core/serialize.py
# def json_serialize(obj):
#     from datetime import datetime
#     # from golem.core.entities import Entity
#     if isinstance(obj, datetime):
#         return {'__type__':'datetime', 'value': obj.isoformat()}
#     elif isinstance(obj, EntityValue):
#         data = b64encode(pickle.dumps(obj))
#         return {"__data__": data.decode('utf8'), '__type__': 'entity'}
#     raise TypeError ("Error saving entity value. Type %s not serializable: %s" % (type(obj), obj))


import json
from abc import ABC, abstractmethod
from golem.core.responses.responses import MessageElement
from golem.core.serialize import json_serialize


class Button(MessageElement, ABC):
    """
    An abstract chat button. Don't use this class directly.
    """

    @abstractmethod
    def to_response(self):
        raise NotImplementedError('Abstract method')

    @abstractmethod
    def __str__(self):
        raise NotImplementedError('Abstract method')


class PayloadButton(Button):
    """
    A button that sends predefined data back to the bot when clicked.
    """

    def __init__(self, title, payload):
        super(Button, self).__init__()
        self.title = title
        self.payload = payload

    def to_response(self):
        return {
            'title': self.title,
            'type': 'postback',

# Path: golem/core/responses/responses.py
# class MessageElement:
#     """
#     Base class for message elements.
#     """
#     def to_message(self, fbid):
#         return {"recipient": {"id": fbid}, "message": self.to_response()}
# 
#     def to_response(self):
#         pass
# 
#     def get_response_for(self, platform='fb'):
#         return str(self)  # TODO
# 
#     def set_message_tag(self, tag):
#         self.tag = tag
# 
#     def get_message_tag(self):
#         """
#         See https://developers.facebook.com/docs/messenger-platform/send-messages/message-tags
#         :return: FB message tag
#         """
#         if hasattr(self, "tag"):
#             return self.tag
#         return None
# 
#     def __str__(self):
#         return str(self.__dict__)
# 
#     def __repr__(self):
#         return str(self)
# 
# Path: golem/core/serialize.py
# def json_serialize(obj):
#     from datetime import datetime
#     # from golem.core.entities import Entity
#     if isinstance(obj, datetime):
#         return {'__type__':'datetime', 'value': obj.isoformat()}
#     elif isinstance(obj, EntityValue):
#         data = b64encode(pickle.dumps(obj))
#         return {"__data__": data.decode('utf8'), '__type__': 'entity'}
#     raise TypeError ("Error saving entity value. Type %s not serializable: %s" % (type(obj), obj))


# Path: golem/core/responses/buttons.py
import json
from abc import ABC, abstractmethod
from golem.core.responses.responses import MessageElement
from golem.core.serialize import json_serialize



class Button(MessageElement, ABC):
    """
    An abstract chat button. Don't use this class directly.
    """

    @abstractmethod
    def to_response(self):
        raise NotImplementedError('Abstract method')

    @abstractmethod
    def __str__(self):
        raise NotImplementedError('Abstract method')


class PayloadButton(Button):
    """
    A button that sends predefined data back to the bot when clicked.
    """

    def __init__(self, title, payload):
        super(Button, self).__init__()
        self.title = title
        self.payload = payload

    def to_response(self):
        return {
            'title': self.title,
            'type': 'postback',

            'payload': json.dumps(self.payload, default=json_serialize)