from ....tl.mtproto_request import MTProtoRequest


class UpdateUsernameRequest(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    account.updateUsername#3e0bdd7c username:string = User"""

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

    def __init__(self, username):
        """
        :param username: Telegram type: "string".

        :returns User: Instance of either UserEmpty, User.
        """
        super().__init__()
        self.result = None
        self.confirmed = True  # Confirmed by default

        self.username = username

    def to_dict(self):
        return {
            'username': self.username,
        }

    def on_send(self, writer):
        writer.write_int(UpdateUsernameRequest.constructor_id, signed=False)
        writer.tgwrite_string(self.username)

    @staticmethod
    def empty():
        """Returns an "empty" instance (attributes=None)"""
        return UpdateUsernameRequest(None)

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

    def __repr__(self):
        return 'account.updateUsername#3e0bdd7c username:string = User'

    def __str__(self):
        return '(account.updateUsername (ID: 0x3e0bdd7c) = (username={}))'.format(str(self.username))
