from ....tl.tlobject import TLObject


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

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

    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.content_related = True

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

    def to_dict(self):
        return {
            'success': self.success,
            'query_id': self.query_id,
            'error': self.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 (attributes=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 TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
