from ...tl.tlobject import TLObject


class ChannelForbidden(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat"""

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

    def __init__(self, id, access_hash, title, broadcast=None, megagroup=None, until_date=None):
        """
        :param broadcast: Telegram type: "true".
        :param megagroup: Telegram type: "true".
        :param id: Telegram type: "int".
        :param access_hash: Telegram type: "long".
        :param title: Telegram type: "string".
        :param until_date: Telegram type: "date".

        Constructor for Chat: Instance of either ChatEmpty, Chat, ChatForbidden, Channel, ChannelForbidden.
        """
        super().__init__()

        self.broadcast = broadcast
        self.megagroup = megagroup
        self.id = id
        self.access_hash = access_hash
        self.title = title
        self.until_date = until_date

    def to_dict(self):
        return {
            'broadcast': self.broadcast,
            'megagroup': self.megagroup,
            'id': self.id,
            'access_hash': self.access_hash,
            'title': self.title,
            'until_date': self.until_date,
        }

    def on_send(self, writer):
        writer.write_int(ChannelForbidden.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 5) if self.broadcast else 0
        flags |= (1 << 8) if self.megagroup else 0
        flags |= (1 << 16) if self.until_date else 0
        writer.write_int(flags)

        writer.write_int(self.id)
        writer.write_long(self.access_hash)
        writer.tgwrite_string(self.title)
        if self.until_date:
            writer.tgwrite_date(self.until_date)

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

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

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

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

        self.id = reader.read_int()
        self.access_hash = reader.read_long()
        self.title = reader.tgread_string()
        if (flags & (1 << 16)) != 0:
            self.until_date = reader.tgread_date()

    def __repr__(self):
        return 'channelForbidden#289da732 flags:# broadcast:flags.5?true megagroup:flags.8?true id:int access_hash:long title:string until_date:flags.16?int = Chat'

    def __str__(self):
        return TLObject.pretty_format(self)

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