from telethon.tl.mtproto_request import MTProtoRequest


class SetGameScoreRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    messages.setGameScore#8ef8ecc0 flags:None edit_message:flags.0?true peer:InputPeer id:int user_id:InputUser score:int = Updates"""

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

    def __init__(self, peer, id, user_id, score, edit_message=None):
        """
        :param edit_message: Telegram type: «true».
        :param peer: Telegram type: «InputPeer».
        :param id: Telegram type: «int».
        :param user_id: Telegram type: «InputUser».
        :param score: Telegram type: «int».
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.edit_message = edit_message
        self.peer = peer
        self.id = id
        self.user_id = user_id
        self.score = score

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

        self.peer.on_send(writer)
        writer.write_int(self.id)
        self.user_id.on_send(writer)
        writer.write_int(self.score)

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

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

    def __repr__(self):
        return 'messages.setGameScore#8ef8ecc0 flags:None edit_message:flags.0?true peer:InputPeer id:int user_id:InputUser score:int = Updates'

    def __str__(self):
        return '(messages.setGameScore (ID: 0x8ef8ecc0) = (edit_message={}, peer={}, id={}, user_id={}, score={}))'.format(str(self.edit_message), str(self.peer), str(self.id), str(self.user_id), str(self.score))
