from ....tl.mtproto_request import MTProtoRequest
from ....utils import get_input_peer


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

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

    def __init__(self, peer, id, user_id, score, edit_message=None, force=None):
        """
        :param edit_message: Telegram type: "true".
        :param force: Telegram type: "true".
        :param peer: Telegram type: "InputPeer".
        :param id: Telegram type: "int".
        :param user_id: Telegram type: "InputUser".
        :param score: Telegram type: "int".

        :returns Updates: Instance of either UpdatesTooLong, UpdateShortMessage, UpdateShortChatMessage, UpdateShort, UpdatesCombined, UpdatesTg, UpdateShortSentMessage.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.edit_message = edit_message
        self.force = force
        self.peer = get_input_peer(peer)
        self.id = id
        self.user_id = user_id
        self.score = score

    def to_dict(self):
        return {
            'edit_message': self.edit_message,
            'force': self.force,
            'peer': None if self.peer is None else self.peer.to_dict(),
            'id': self.id,
            'user_id': None if self.user_id is None else self.user_id.to_dict(),
            'score': self.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
        flags |= (1 << 1) if self.force 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 (attributes=None)"""
        return SetGameScoreRequest(None, None, None, None, None, None)

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

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

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