from typing import Optional, Any, Dict
from ._DataType import DataType


class Message(object):
    def __init__(
        self,                           # type: Message
        token,                          # type: int
        data_type=DataType.empty,       # type: int
        data=None,                      # type: bytes
        timeout=-1,                     # type: int
        headers=None,                   # type: Dict[str, str]
        ttl=-1,                         # type: int
    ):
        # type: (...) -> None
        self.token = token
        self.data_type = data_type
        self.data = data
        self.timeout = timeout
        self.headers = headers if headers is not None else {}
        self.ttl = ttl
        self.imp_message = None  # type: Any

    def __eq__(self, o):
        # type: (object) -> bool
        if not isinstance(o, Message):
            return False

        return (
            self.token == o.token
            and self.data_type == o.data_type
            and self.data == o.data
            and self.timeout == o.timeout
            and self.headers == o.headers
            and self.ttl == o.ttl
        )

    def __ne__(self, o):
        # type: (object) -> bool
        return not self.__eq__(o)

    def __str__(self):
        return str({
            "token": self.token,
            "data_type": self.data_type,
            "timeout": self.timeout,
            "headers": self.headers,
            "ttl": self.ttl,
        })
