from ....tl.mtproto_request import MTProtoRequest


class SetBotCallbackAnswerRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messages.setBotCallbackAnswer#d58f130a flags:# alert:flags.1?true query_id:long message:flags.0?string url:flags.2?string cache_time:int = Bool"""

    # Telegram's constructor (U)ID for this class
    constructor_id = 0xd58f130a
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0xf5b399ac

    def __init__(self, query_id, cache_time, alert=None, message=None, url=None):
        """
        :param alert: Telegram type: "true".
        :param query_id: Telegram type: "long".
        :param message: Telegram type: "string".
        :param url: Telegram type: "string".
        :param cache_time: Telegram type: "int".

        :returns Bool: This type has no constructors.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.alert = alert
        self.query_id = query_id
        self.message = message
        self.url = url
        self.cache_time = cache_time

    def to_dict(self):
        return {
            'alert': self.alert,
            'query_id': self.query_id,
            'message': self.message,
            'url': self.url,
            'cache_time': self.cache_time,
        }

    def on_send(self, writer):
        writer.write_int(SetBotCallbackAnswerRequest.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 1) if self.alert else 0
        flags |= (1 << 0) if self.message else 0
        flags |= (1 << 2) if self.url else 0
        writer.write_int(flags)

        writer.write_long(self.query_id)
        if self.message:
            writer.tgwrite_string(self.message)

        if self.url:
            writer.tgwrite_string(self.url)

        writer.write_int(self.cache_time)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return SetBotCallbackAnswerRequest(None, None, None, None, None)

    def on_response(self, reader):
        self.result = reader.tgread_object()

    def __repr__(self):
        return 'messages.setBotCallbackAnswer#d58f130a flags:# alert:flags.1?true query_id:long message:flags.0?string url:flags.2?string cache_time:int = Bool'

    def __str__(self):
        return '(messages.setBotCallbackAnswer (ID: 0xd58f130a) = (alert={}, query_id={}, message={}, url={}, cache_time={}))'.format(str(self.alert), str(self.query_id), str(self.message), str(self.url), str(self.cache_time))
