from ...tl.mtproto_request import MTProtoRequest


class PhoneCallRequested(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    phoneCallRequested#83761ce4 id:long access_hash:long date:int admin_id:int participant_id:int g_a_hash:bytes protocol:PhoneCallProtocol = PhoneCall"""

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

    def __init__(self, id, access_hash, date, admin_id, participant_id, g_a_hash, protocol):
        """
        :param id: Telegram type: "long".
        :param access_hash: Telegram type: "long".
        :param date: Telegram type: "date".
        :param admin_id: Telegram type: "int".
        :param participant_id: Telegram type: "int".
        :param g_a_hash: Telegram type: "bytes".
        :param protocol: Telegram type: "PhoneCallProtocol".

        Constructor for PhoneCall: Instance of either PhoneCallEmpty, PhoneCallWaiting, PhoneCallRequested, PhoneCallAccepted, PhoneCall, PhoneCallDiscarded.
        """
        super().__init__()

        self.id = id
        self.access_hash = access_hash
        self.date = date
        self.admin_id = admin_id
        self.participant_id = participant_id
        self.g_a_hash = g_a_hash
        self.protocol = protocol

    def to_dict(self):
        return {
            'id': self.id,
            'access_hash': self.access_hash,
            'date': self.date,
            'admin_id': self.admin_id,
            'participant_id': self.participant_id,
            'g_a_hash': self.g_a_hash,
            'protocol': None if self.protocol is None else self.protocol.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(PhoneCallRequested.constructor_id, signed=False)
        writer.write_long(self.id)
        writer.write_long(self.access_hash)
        writer.tgwrite_date(self.date)
        writer.write_int(self.admin_id)
        writer.write_int(self.participant_id)
        writer.tgwrite_bytes(self.g_a_hash)
        self.protocol.on_send(writer)

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

    def on_response(self, reader):
        self.id = reader.read_long()
        self.access_hash = reader.read_long()
        self.date = reader.tgread_date()
        self.admin_id = reader.read_int()
        self.participant_id = reader.read_int()
        self.g_a_hash = reader.tgread_bytes()
        self.protocol = reader.tgread_object()

    def __repr__(self):
        return 'phoneCallRequested#83761ce4 id:long access_hash:long date:int admin_id:int participant_id:int g_a_hash:bytes protocol:PhoneCallProtocol = PhoneCall'

    def __str__(self):
        return '(phoneCallRequested (ID: 0x83761ce4) = (id={}, access_hash={}, date={}, admin_id={}, participant_id={}, g_a_hash={}, protocol={}))'.format(str(self.id), str(self.access_hash), str(self.date), str(self.admin_id), str(self.participant_id), str(self.g_a_hash), str(self.protocol))
