from ...tl.mtproto_request import MTProtoRequest


class DocumentAttributeVideo(MTProtoRequest):
    """Class generated by TLObjects' generator. All changes will be ERASED. Original .tl definition below.
    documentAttributeVideo#0ef02ce6 flags:# round_message:flags.0?true duration:int w:int h:int = DocumentAttribute"""

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

    def __init__(self, duration, w, h, round_message=None):
        """
        :param round_message: Telegram type: «true».
        :param duration: Telegram type: «int».
        :param w: Telegram type: «int».
        :param h: Telegram type: «int».

        Constructor for DocumentAttribute: Instance of either DocumentAttributeImageSize, DocumentAttributeAnimated, DocumentAttributeSticker, DocumentAttributeVideo, DocumentAttributeAudio, DocumentAttributeFilename, DocumentAttributeHasStickers.
        """
        super().__init__()

        self.round_message = round_message
        self.duration = duration
        self.w = w
        self.h = h

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

        writer.write_int(self.duration)
        writer.write_int(self.w)
        writer.write_int(self.h)

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

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

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

        self.duration = reader.read_int()
        self.w = reader.read_int()
        self.h = reader.read_int()

    def __repr__(self):
        return 'documentAttributeVideo#0ef02ce6 flags:# round_message:flags.0?true duration:int w:int h:int = DocumentAttribute'

    def __str__(self):
        return '(documentAttributeVideo (ID: 0xef02ce6) = (round_message={}, duration={}, w={}, h={}))'.format(str(self.round_message), str(self.duration), str(self.w), str(self.h))
