from ....tl.mtproto_request import MTProtoRequest


class ChannelDifferenceEmpty(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    updates.channelDifferenceEmpty#3e11affb flags:# final:flags.0?true pts:int timeout:flags.1?int = updates.ChannelDifference"""

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

    def __init__(self, pts, final=None, timeout=None):
        """
        :param final: Telegram type: «true».
        :param pts: Telegram type: «int».
        :param timeout: Telegram type: «int».

        Constructor for updates.ChannelDifference: Instance of either ChannelDifferenceEmpty, ChannelDifferenceTooLong, ChannelDifference.
        """
        super().__init__()

        self.final = final
        self.pts = pts
        self.timeout = timeout

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

        writer.write_int(self.pts)
        if self.timeout:
            writer.write_int(self.timeout)

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

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.final = True  # Arbitrary not-None value, no need to read since it is a flag

        self.pts = reader.read_int()
        if (flags & (1 << 1)) != 0:
            self.timeout = reader.read_int()

    def __repr__(self):
        return 'updates.channelDifferenceEmpty#3e11affb flags:# final:flags.0?true pts:int timeout:flags.1?int = updates.ChannelDifference'

    def __str__(self):
        return '(updates.channelDifferenceEmpty (ID: 0x3e11affb) = (final={}, pts={}, timeout={}))'.format(str(self.final), str(self.pts), str(self.timeout))
