from ....tl.mtproto_request import MTProtoRequest


class SetBotPrecheckoutResultsRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.setBotPrecheckoutResults#09c2dd95 flags:# success:flags.1?true query_id:long error:flags.0?string = Bool"""

    # Telegram's constructor ID (and unique identifier) for this class
    constructor_id = 0x9c2dd95

    def __init__(self, query_id, success=None, error=None):
        """
        :param success: Telegram type: «true».
        :param query_id: Telegram type: «long».
        :param error: Telegram type: «string».

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

        self.success = success
        self.query_id = query_id
        self.error = error

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

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

    @staticmethod
    def empty():
        """Returns an "empty" instance (all attributes are None)"""
        return SetBotPrecheckoutResultsRequest(None, None, None)

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

    def __repr__(self):
        return 'messages.setBotPrecheckoutResults#09c2dd95 flags:# success:flags.1?true query_id:long error:flags.0?string = Bool'

    def __str__(self):
        return '(messages.setBotPrecheckoutResults (ID: 0x9c2dd95) = (success={}, query_id={}, error={}))'.format(str(self.success), str(self.query_id), str(self.error))
