from ...tl.mtproto_request import MTProtoRequest


class PhoneCallProtocol(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    phoneCallProtocol#a2bb35cb flags:# udp_p2p:flags.0?true udp_reflector:flags.1?true min_layer:int max_layer:int = PhoneCallProtocol"""

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

    def __init__(self, min_layer, max_layer, udp_p2p=None, udp_reflector=None):
        """
        :param udp_p2p: Telegram type: «true».
        :param udp_reflector: Telegram type: «true».
        :param min_layer: Telegram type: «int».
        :param max_layer: Telegram type: «int».

        Constructor for PhoneCallProtocol: Instance of PhoneCallProtocol.
        """
        super().__init__()

        self.udp_p2p = udp_p2p
        self.udp_reflector = udp_reflector
        self.min_layer = min_layer
        self.max_layer = max_layer

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

        writer.write_int(self.min_layer)
        writer.write_int(self.max_layer)

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

    def on_response(self, reader):
        flags = reader.read_int()

        if (flags & (1 << 0)) != 0:
            self.udp_p2p = True  # Arbitrary not-None value, no need to read since it is a flag

        if (flags & (1 << 1)) != 0:
            self.udp_reflector = True  # Arbitrary not-None value, no need to read since it is a flag

        self.min_layer = reader.read_int()
        self.max_layer = reader.read_int()

    def __repr__(self):
        return 'phoneCallProtocol#a2bb35cb flags:# udp_p2p:flags.0?true udp_reflector:flags.1?true min_layer:int max_layer:int = PhoneCallProtocol'

    def __str__(self):
        return '(phoneCallProtocol (ID: 0xa2bb35cb) = (udp_p2p={}, udp_reflector={}, min_layer={}, max_layer={}))'.format(str(self.udp_p2p), str(self.udp_reflector), str(self.min_layer), str(self.max_layer))
