from ....tl.mtproto_request import MTProtoRequest


class GetDifferenceRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:date qts:int = updates.Difference"""

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

    def __init__(self, pts, date, qts, pts_total_limit=None):
        """
        :param pts: Telegram type: «int».
        :param pts_total_limit: Telegram type: «int».
        :param date: Telegram type: «date».
        :param qts: Telegram type: «int».

        :returns updates.Difference: Instance of either DifferenceEmpty, Difference, DifferenceSlice, DifferenceTooLong.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.pts = pts
        self.pts_total_limit = pts_total_limit
        self.date = date
        self.qts = qts

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

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

        writer.tgwrite_date(self.date)
        writer.write_int(self.qts)

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

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

    def __repr__(self):
        return 'updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:date qts:int = updates.Difference'

    def __str__(self):
        return '(updates.getDifference (ID: 0x25939651) = (pts={}, pts_total_limit={}, date={}, qts={}))'.format(str(self.pts), str(self.pts_total_limit), str(self.date), str(self.qts))
