from ...tl.tlobject import TLObject


class PhoneCallProtocol(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. 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 (U)ID for this class
    constructor_id = 0xa2bb35cb
    # Also the ID of its resulting type for fast checks
    subclass_of_id = 0x783991a3

    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 to_dict(self):
        return {
            'udp_p2p': self.udp_p2p,
            'udp_reflector': self.udp_reflector,
            'min_layer': self.min_layer,
            'max_layer': self.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 (attributes=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 TLObject.pretty_format(self)

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