from ....tl.tlobject import TLObject
from ....utils import get_input_user
import os


class RequestEncryptionRequest(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    messages.requestEncryption#f64daf43 user_id:InputUser random_id:int g_a:bytes = EncryptedChat"""

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

    def __init__(self, user_id, g_a, random_id=None):
        """
        :param user_id: Telegram type: "InputUser".
        :param random_id: Telegram type: "int".
        :param g_a: Telegram type: "bytes".

        :returns EncryptedChat: Instance of either EncryptedChatEmpty, EncryptedChatWaiting, EncryptedChatRequested, EncryptedChat, EncryptedChatDiscarded.
        """
        super().__init__()
        self.result = None
        self.content_related = True

        self.user_id = get_input_user(user_id)
        self.random_id = random_id if random_id is not None else int.from_bytes(os.urandom(4), signed=True, byteorder='little')
        self.g_a = g_a

    def to_dict(self):
        return {
            'user_id': None if self.user_id is None else self.user_id.to_dict(),
            'random_id': self.random_id,
            'g_a': self.g_a,
        }

    def on_send(self, writer):
        writer.write_int(RequestEncryptionRequest.constructor_id, signed=False)
        self.user_id.on_send(writer)
        writer.write_int(self.random_id)
        writer.tgwrite_bytes(self.g_a)

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

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

    def __repr__(self):
        return 'messages.requestEncryption#f64daf43 user_id:InputUser random_id:int g_a:bytes = EncryptedChat'

    def __str__(self):
        return TLObject.pretty_format(self)

    def stringify(self):
        return TLObject.pretty_format(self, indent=0)
