from ...tl.mtproto_request import MTProtoRequest


class InputPeerNotifySettings(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    inputPeerNotifySettings#38935eb2 flags:# show_previews:flags.0?true silent:flags.1?true mute_until:int sound:string = InputPeerNotifySettings"""

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

    def __init__(self, mute_until, sound, show_previews=None, silent=None):
        """
        :param show_previews: Telegram type: «true».
        :param silent: Telegram type: «true».
        :param mute_until: Telegram type: «int».
        :param sound: Telegram type: «string».

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

        self.show_previews = show_previews
        self.silent = silent
        self.mute_until = mute_until
        self.sound = sound

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

        writer.write_int(self.mute_until)
        writer.tgwrite_string(self.sound)

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

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

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

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

        self.mute_until = reader.read_int()
        self.sound = reader.tgread_string()

    def __repr__(self):
        return 'inputPeerNotifySettings#38935eb2 flags:# show_previews:flags.0?true silent:flags.1?true mute_until:int sound:string = InputPeerNotifySettings'

    def __str__(self):
        return '(inputPeerNotifySettings (ID: 0x38935eb2) = (show_previews={}, silent={}, mute_until={}, sound={}))'.format(str(self.show_previews), str(self.silent), str(self.mute_until), str(self.sound))
