from ...tl.tlobject import TLObject


class Channel(TLObject):
    """Class generated by TLObjects' generator. All changes will be ERASED. TL definition below.
    channel#0cb44b1c flags:# creator:flags.0?true left:flags.2?true editor:flags.3?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights = Chat"""

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

    def __init__(self, id, title, photo, date, version, creator=None, left=None, editor=None, broadcast=None, verified=None, megagroup=None, restricted=None, democracy=None, signatures=None, min=None, access_hash=None, username=None, restriction_reason=None, admin_rights=None, banned_rights=None):
        """
        :param creator: Telegram type: "true".
        :param left: Telegram type: "true".
        :param editor: Telegram type: "true".
        :param broadcast: Telegram type: "true".
        :param verified: Telegram type: "true".
        :param megagroup: Telegram type: "true".
        :param restricted: Telegram type: "true".
        :param democracy: Telegram type: "true".
        :param signatures: Telegram type: "true".
        :param min: Telegram type: "true".
        :param id: Telegram type: "int".
        :param access_hash: Telegram type: "long".
        :param title: Telegram type: "string".
        :param username: Telegram type: "string".
        :param photo: Telegram type: "ChatPhoto".
        :param date: Telegram type: "date".
        :param version: Telegram type: "int".
        :param restriction_reason: Telegram type: "string".
        :param admin_rights: Telegram type: "ChannelAdminRights".
        :param banned_rights: Telegram type: "ChannelBannedRights".

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

        self.creator = creator
        self.left = left
        self.editor = editor
        self.broadcast = broadcast
        self.verified = verified
        self.megagroup = megagroup
        self.restricted = restricted
        self.democracy = democracy
        self.signatures = signatures
        self.min = min
        self.id = id
        self.access_hash = access_hash
        self.title = title
        self.username = username
        self.photo = photo
        self.date = date
        self.version = version
        self.restriction_reason = restriction_reason
        self.admin_rights = admin_rights
        self.banned_rights = banned_rights

    def to_dict(self):
        return {
            'creator': self.creator,
            'left': self.left,
            'editor': self.editor,
            'broadcast': self.broadcast,
            'verified': self.verified,
            'megagroup': self.megagroup,
            'restricted': self.restricted,
            'democracy': self.democracy,
            'signatures': self.signatures,
            'min': self.min,
            'id': self.id,
            'access_hash': self.access_hash,
            'title': self.title,
            'username': self.username,
            'photo': None if self.photo is None else self.photo.to_dict(),
            'date': self.date,
            'version': self.version,
            'restriction_reason': self.restriction_reason,
            'admin_rights': None if self.admin_rights is None else self.admin_rights.to_dict(),
            'banned_rights': None if self.banned_rights is None else self.banned_rights.to_dict(),
        }

    def on_send(self, writer):
        writer.write_int(Channel.constructor_id, signed=False)
        # Calculate the flags. This equals to those flag arguments which are NOT None
        flags = 0
        flags |= (1 << 0) if self.creator else 0
        flags |= (1 << 2) if self.left else 0
        flags |= (1 << 3) if self.editor else 0
        flags |= (1 << 5) if self.broadcast else 0
        flags |= (1 << 7) if self.verified else 0
        flags |= (1 << 8) if self.megagroup else 0
        flags |= (1 << 9) if self.restricted else 0
        flags |= (1 << 10) if self.democracy else 0
        flags |= (1 << 11) if self.signatures else 0
        flags |= (1 << 12) if self.min else 0
        flags |= (1 << 13) if self.access_hash else 0
        flags |= (1 << 6) if self.username else 0
        flags |= (1 << 9) if self.restriction_reason else 0
        flags |= (1 << 14) if self.admin_rights else 0
        flags |= (1 << 15) if self.banned_rights else 0
        writer.write_int(flags)

        writer.write_int(self.id)
        if self.access_hash:
            writer.write_long(self.access_hash)

        writer.tgwrite_string(self.title)
        if self.username:
            writer.tgwrite_string(self.username)

        self.photo.on_send(writer)
        writer.tgwrite_date(self.date)
        writer.write_int(self.version)
        if self.restriction_reason:
            writer.tgwrite_string(self.restriction_reason)

        if self.admin_rights:
            self.admin_rights.on_send(writer)

        if self.banned_rights:
            self.banned_rights.on_send(writer)

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

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

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

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

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

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

        if (flags & (1 << 7)) != 0:
            self.verified = 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

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

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

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

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

        self.id = reader.read_int()
        if (flags & (1 << 13)) != 0:
            self.access_hash = reader.read_long()

        self.title = reader.tgread_string()
        if (flags & (1 << 6)) != 0:
            self.username = reader.tgread_string()

        self.photo = reader.tgread_object()
        self.date = reader.tgread_date()
        self.version = reader.read_int()
        if (flags & (1 << 9)) != 0:
            self.restriction_reason = reader.tgread_string()

        if (flags & (1 << 14)) != 0:
            self.admin_rights = reader.tgread_object()

        if (flags & (1 << 15)) != 0:
            self.banned_rights = reader.tgread_object()

    def __repr__(self):
        return 'channel#0cb44b1c flags:# creator:flags.0?true left:flags.2?true editor:flags.3?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true democracy:flags.10?true signatures:flags.11?true min:flags.12?true id:int access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int version:int restriction_reason:flags.9?string admin_rights:flags.14?ChannelAdminRights banned_rights:flags.15?ChannelBannedRights = Chat'

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

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