// <auto-generated/>
// ReSharper disable All

namespace MyTelegram.Schema;

///<summary>
/// Channel/supergroup infoWhen updating the <a href="https://corefork.telegram.org/api/peers">local peer database</a>, all fields from the newly received constructor take priority over the old constructor cached locally (including by removing fields that aren't set in the new constructor).The only exception to the above rule is when the <code>min</code> flag is set, in which case <strong>only</strong> the following fields must be applied over any locally stored version:See <a href="https://github.com/tdlib/td/blob/a24af0992245f838f2b4b418a0a2d5fa9caa27b5/td/telegram/ChatManager.cpp#L8329">here »</a> for an implementation of the logic to use when updating the <a href="https://corefork.telegram.org/api/peers">local user peer database</a>.
/// See <a href="https://corefork.telegram.org/constructor/channel" />
///</summary>
[TlObject(0xfe685355)]
public sealed class TChannel : MyTelegram.Schema.IChat, ILayeredChannel
{
    public uint ConstructorId => 0xfe685355;
    ///<summary>
    /// Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a>
    ///</summary>
    public int Flags { get; set; }

    ///<summary>
    /// Whether the current user is the creator of this channel
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Creator { get; set; }

    ///<summary>
    /// Whether the current user has left or is not a member of this channel
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Left { get; set; }

    ///<summary>
    /// Is this a channel?
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Broadcast { get; set; }

    ///<summary>
    /// Is this channel verified by telegram?
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Verified { get; set; }

    ///<summary>
    /// Is this a supergroup? <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Megagroup { get; set; }

    ///<summary>
    /// Whether viewing/writing in this channel for a reason (see <code>restriction_reason</code>)
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Restricted { get; set; }

    ///<summary>
    /// Whether signatures are enabled (channels)
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Signatures { get; set; }

    ///<summary>
    /// See <a href="https://corefork.telegram.org/api/min">min</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Min { get; set; }

    ///<summary>
    /// This channel/supergroup is probably a scam <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Scam { get; set; }

    ///<summary>
    /// Whether this channel has a linked <a href="https://corefork.telegram.org/api/discussion">discussion group »</a> (or this supergroup is a channel's discussion group). The actual ID of the linked channel/supergroup is contained in <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a>.<code>linked_chat_id</code>. <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HasLink { get; set; }

    ///<summary>
    /// Whether this chanel has a geoposition
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HasGeo { get; set; }

    ///<summary>
    /// Whether slow mode is enabled for groups to prevent flood in chat. <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SlowmodeEnabled { get; set; }

    ///<summary>
    /// Whether a group call or livestream is currently active
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool CallActive { get; set; }

    ///<summary>
    /// Whether there's anyone in the group call or livestream
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool CallNotEmpty { get; set; }

    ///<summary>
    /// If set, this <a href="https://corefork.telegram.org/api/channel">supergroup/channel</a> was reported by many users as a fake or scam: be careful when interacting with it. <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Fake { get; set; }

    ///<summary>
    /// Whether this <a href="https://corefork.telegram.org/api/channel">supergroup</a> is a gigagroup<br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Gigagroup { get; set; }

    ///<summary>
    /// Whether this channel or group is <a href="https://telegram.org/blog/protected-content-delete-by-date-and-more">protected</a>, thus does not allow forwarding messages from it
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Noforwards { get; set; }

    ///<summary>
    /// Whether a user needs to join the supergroup before they can send messages: can be false only for <a href="https://corefork.telegram.org/api/discussion">discussion groups »</a>, toggle using <a href="https://corefork.telegram.org/method/channels.toggleJoinToSend">channels.toggleJoinToSend</a><br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool JoinToSend { get; set; }

    ///<summary>
    /// Whether a user's join request will have to be <a href="https://corefork.telegram.org/api/invites#join-requests">approved by administrators</a>, toggle using <a href="https://corefork.telegram.org/method/channels.toggleJoinRequest">channels.toggleJoinToSend</a><br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool JoinRequest { get; set; }

    ///<summary>
    /// Whether this supergroup is a <a href="https://corefork.telegram.org/api/forum">forum</a>. <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Forum { get; set; }

    ///<summary>
    /// Flags, see <a href="https://corefork.telegram.org/mtproto/TL-combinators#conditional-fields">TL conditional fields</a>
    ///</summary>
    public int Flags2 { get; set; }

    ///<summary>
    /// Whether we have <a href="https://corefork.telegram.org/api/stories#hiding-stories-of-other-users">hidden all stories posted by this channel »</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool StoriesHidden { get; set; }

    ///<summary>
    /// If set, indicates that the <code>stories_hidden</code> flag was not populated, and its value must cannot be relied on; use the previously cached value, or re-fetch the constructor using <a href="https://corefork.telegram.org/method/channels.getChannels">channels.getChannels</a> to obtain the latest value of the <code>stories_hidden</code> flag.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool StoriesHiddenMin { get; set; }

    ///<summary>
    /// No stories from the channel are visible.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool StoriesUnavailable { get; set; }

    ///<summary>
    /// If set, messages sent by admins to this channel will link to the admin's profile (just like with groups).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SignatureProfiles { get; set; }
    public bool Autotranslation { get; set; }
    public bool BroadcastMessagesAllowed { get; set; }
    public bool Monoforum { get; set; }
    public bool ForumTabs { get; set; }

    ///<summary>
    /// ID of the channel, see <a href="https://corefork.telegram.org/api/peers#peer-id">here »</a> for more info
    ///</summary>
    public long Id { get; set; }

    ///<summary>
    /// Access hash, see <a href="https://corefork.telegram.org/api/peers#access-hash">here »</a> for more info
    ///</summary>
    public long? AccessHash { get; set; }

    ///<summary>
    /// Title
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// Main active username.
    ///</summary>
    public string? Username { get; set; }

    ///<summary>
    /// Profile photo
    /// See <a href="https://corefork.telegram.org/type/ChatPhoto" />
    ///</summary>
    public MyTelegram.Schema.IChatPhoto Photo { get; set; }

    ///<summary>
    /// Date when the user joined the supergroup/channel, or if the user isn't a member, its creation date
    ///</summary>
    public int Date { get; set; }

    ///<summary>
    /// Contains the reason why access to this channel must be restricted. <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    ///</summary>
    public TVector<MyTelegram.Schema.IRestrictionReason>? RestrictionReason { get; set; }

    ///<summary>
    /// Admin rights of the user in this channel (see <a href="https://corefork.telegram.org/api/rights">rights</a>)
    /// See <a href="https://corefork.telegram.org/type/ChatAdminRights" />
    ///</summary>
    public MyTelegram.Schema.IChatAdminRights? AdminRights { get; set; }

    ///<summary>
    /// Banned rights of the user in this channel (see <a href="https://corefork.telegram.org/api/rights">rights</a>)
    /// See <a href="https://corefork.telegram.org/type/ChatBannedRights" />
    ///</summary>
    public MyTelegram.Schema.IChatBannedRights? BannedRights { get; set; }

    ///<summary>
    /// Default chat rights (see <a href="https://corefork.telegram.org/api/rights">rights</a>)
    /// See <a href="https://corefork.telegram.org/type/ChatBannedRights" />
    ///</summary>
    public MyTelegram.Schema.IChatBannedRights? DefaultBannedRights { get; set; }

    ///<summary>
    /// Participant count
    ///</summary>
    public int? ParticipantsCount { get; set; }

    ///<summary>
    /// Additional usernames
    ///</summary>
    public TVector<MyTelegram.Schema.IUsername>? Usernames { get; set; }

    ///<summary>
    /// ID of the maximum read <a href="https://corefork.telegram.org/api/stories">story</a>.
    ///</summary>
    public int? StoriesMaxId { get; set; }

    ///<summary>
    /// The channel's <a href="https://corefork.telegram.org/api/colors">accent color</a>.
    /// See <a href="https://corefork.telegram.org/type/PeerColor" />
    ///</summary>
    public MyTelegram.Schema.IPeerColor? Color { get; set; }

    ///<summary>
    /// The channel's <a href="https://corefork.telegram.org/api/colors">profile color</a>.
    /// See <a href="https://corefork.telegram.org/type/PeerColor" />
    ///</summary>
    public MyTelegram.Schema.IPeerColor? ProfileColor { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/emoji-status">Emoji status</a>
    /// See <a href="https://corefork.telegram.org/type/EmojiStatus" />
    ///</summary>
    public MyTelegram.Schema.IEmojiStatus? EmojiStatus { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/boost">Boost level</a>. <br>Changes to this flag should invalidate the local <a href="https://corefork.telegram.org/constructor/channelFull">channelFull</a> cache for this channel/supergroup ID, see <a href="https://corefork.telegram.org/api/peers#full-info-database">here »</a> for more info.
    ///</summary>
    public int? Level { get; set; }

    ///<summary>
    /// Expiration date of the <a href="https://corefork.telegram.org/api/stars#star-subscriptions">Telegram Star subscription »</a> the current user has bought to gain access to this channel.
    ///</summary>
    public int? SubscriptionUntilDate { get; set; }
    public long? BotVerificationIcon { get; set; }
    public long? SendPaidMessagesStars { get; set; }
    public long? LinkedMonoforumId { get; set; }

    public void ComputeFlag()
    {
        if (Creator) { Flags = Flags.SetBit(0); }
        if (Left) { Flags = Flags.SetBit(2); }
        if (Broadcast) { Flags = Flags.SetBit(5); }
        if (Verified) { Flags = Flags.SetBit(7); }
        if (Megagroup) { Flags = Flags.SetBit(8); }
        if (Restricted) { Flags = Flags.SetBit(9); }
        if (Signatures) { Flags = Flags.SetBit(11); }
        if (Min) { Flags = Flags.SetBit(12); }
        if (Scam) { Flags = Flags.SetBit(19); }
        if (HasLink) { Flags = Flags.SetBit(20); }
        if (HasGeo) { Flags = Flags.SetBit(21); }
        if (SlowmodeEnabled) { Flags = Flags.SetBit(22); }
        if (CallActive) { Flags = Flags.SetBit(23); }
        if (CallNotEmpty) { Flags = Flags.SetBit(24); }
        if (Fake) { Flags = Flags.SetBit(25); }
        if (Gigagroup) { Flags = Flags.SetBit(26); }
        if (Noforwards) { Flags = Flags.SetBit(27); }
        if (JoinToSend) { Flags = Flags.SetBit(28); }
        if (JoinRequest) { Flags = Flags.SetBit(29); }
        if (Forum) { Flags = Flags.SetBit(30); }
        if (StoriesHidden) { Flags2 = Flags2.SetBit(1); }
        if (StoriesHiddenMin) { Flags2 = Flags2.SetBit(2); }
        if (StoriesUnavailable) { Flags2 = Flags2.SetBit(3); }
        if (SignatureProfiles) { Flags2 = Flags2.SetBit(12); }
        if (Autotranslation) { Flags2 = Flags2.SetBit(15); }
        if (BroadcastMessagesAllowed) { Flags2 = Flags2.SetBit(16); }
        if (Monoforum) { Flags2 = Flags2.SetBit(17); }
        if (ForumTabs) { Flags2 = Flags2.SetBit(19); }
        if (/*AccessHash != 0 &&*/ AccessHash.HasValue) { Flags = Flags.SetBit(13); }
        if (Username != null) { Flags = Flags.SetBit(6); }
        if (RestrictionReason?.Count > 0) { Flags = Flags.SetBit(9); }
        if (AdminRights != null) { Flags = Flags.SetBit(14); }
        if (BannedRights != null) { Flags = Flags.SetBit(15); }
        if (DefaultBannedRights != null) { Flags = Flags.SetBit(18); }
        if (/*ParticipantsCount != 0 && */ParticipantsCount.HasValue) { Flags = Flags.SetBit(17); }
        if (Usernames?.Count > 0) { Flags2 = Flags2.SetBit(0); }
        if (/*StoriesMaxId != 0 && */StoriesMaxId.HasValue) { Flags2 = Flags2.SetBit(4); }
        if (Color != null) { Flags2 = Flags2.SetBit(7); }
        if (ProfileColor != null) { Flags2 = Flags2.SetBit(8); }
        if (EmojiStatus != null) { Flags2 = Flags2.SetBit(9); }
        if (/*Level != 0 && */Level.HasValue) { Flags2 = Flags2.SetBit(10); }
        if (/*SubscriptionUntilDate != 0 && */SubscriptionUntilDate.HasValue) { Flags2 = Flags2.SetBit(11); }
        if (/*BotVerificationIcon != 0 &&*/ BotVerificationIcon.HasValue) { Flags2 = Flags2.SetBit(13); }
        if (/*SendPaidMessagesStars != 0 &&*/ SendPaidMessagesStars.HasValue) { Flags2 = Flags2.SetBit(14); }
        if (/*LinkedMonoforumId != 0 &&*/ LinkedMonoforumId.HasValue) { Flags2 = Flags2.SetBit(18); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Flags2);
        writer.Write(Id);
        if (Flags.IsBitSet(13)) { writer.Write(AccessHash.Value); }
        writer.Write(Title);
        if (Flags.IsBitSet(6)) { writer.Write(Username); }
        writer.Write(Photo);
        writer.Write(Date);
        if (Flags.IsBitSet(9)) { writer.Write(RestrictionReason); }
        if (Flags.IsBitSet(14)) { writer.Write(AdminRights); }
        if (Flags.IsBitSet(15)) { writer.Write(BannedRights); }
        if (Flags.IsBitSet(18)) { writer.Write(DefaultBannedRights); }
        if (Flags.IsBitSet(17)) { writer.Write(ParticipantsCount.Value); }
        if (Flags2.IsBitSet(0)) { writer.Write(Usernames); }
        if (Flags2.IsBitSet(4)) { writer.Write(StoriesMaxId.Value); }
        if (Flags2.IsBitSet(7)) { writer.Write(Color); }
        if (Flags2.IsBitSet(8)) { writer.Write(ProfileColor); }
        if (Flags2.IsBitSet(9)) { writer.Write(EmojiStatus); }
        if (Flags2.IsBitSet(10)) { writer.Write(Level.Value); }
        if (Flags2.IsBitSet(11)) { writer.Write(SubscriptionUntilDate.Value); }
        if (Flags2.IsBitSet(13)) { writer.Write(BotVerificationIcon.Value); }
        if (Flags2.IsBitSet(14)) { writer.Write(SendPaidMessagesStars.Value); }
        if (Flags2.IsBitSet(18)) { writer.Write(LinkedMonoforumId.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Creator = true; }
        if (Flags.IsBitSet(2)) { Left = true; }
        if (Flags.IsBitSet(5)) { Broadcast = true; }
        if (Flags.IsBitSet(7)) { Verified = true; }
        if (Flags.IsBitSet(8)) { Megagroup = true; }
        if (Flags.IsBitSet(9)) { Restricted = true; }
        if (Flags.IsBitSet(11)) { Signatures = true; }
        if (Flags.IsBitSet(12)) { Min = true; }
        if (Flags.IsBitSet(19)) { Scam = true; }
        if (Flags.IsBitSet(20)) { HasLink = true; }
        if (Flags.IsBitSet(21)) { HasGeo = true; }
        if (Flags.IsBitSet(22)) { SlowmodeEnabled = true; }
        if (Flags.IsBitSet(23)) { CallActive = true; }
        if (Flags.IsBitSet(24)) { CallNotEmpty = true; }
        if (Flags.IsBitSet(25)) { Fake = true; }
        if (Flags.IsBitSet(26)) { Gigagroup = true; }
        if (Flags.IsBitSet(27)) { Noforwards = true; }
        if (Flags.IsBitSet(28)) { JoinToSend = true; }
        if (Flags.IsBitSet(29)) { JoinRequest = true; }
        if (Flags.IsBitSet(30)) { Forum = true; }
        Flags2 = buffer.ReadInt32();
        if (Flags2.IsBitSet(1)) { StoriesHidden = true; }
        if (Flags2.IsBitSet(2)) { StoriesHiddenMin = true; }
        if (Flags2.IsBitSet(3)) { StoriesUnavailable = true; }
        if (Flags2.IsBitSet(12)) { SignatureProfiles = true; }
        if (Flags2.IsBitSet(15)) { Autotranslation = true; }
        if (Flags2.IsBitSet(16)) { BroadcastMessagesAllowed = true; }
        if (Flags2.IsBitSet(17)) { Monoforum = true; }
        if (Flags2.IsBitSet(19)) { ForumTabs = true; }
        Id = buffer.ReadInt64();
        if (Flags.IsBitSet(13)) { AccessHash = buffer.ReadInt64(); }
        Title = buffer.ReadString();
        if (Flags.IsBitSet(6)) { Username = buffer.ReadString(); }
        Photo = buffer.Read<MyTelegram.Schema.IChatPhoto>();
        Date = buffer.ReadInt32();
        if (Flags.IsBitSet(9)) { RestrictionReason = buffer.Read<TVector<MyTelegram.Schema.IRestrictionReason>>(); }
        if (Flags.IsBitSet(14)) { AdminRights = buffer.Read<MyTelegram.Schema.IChatAdminRights>(); }
        if (Flags.IsBitSet(15)) { BannedRights = buffer.Read<MyTelegram.Schema.IChatBannedRights>(); }
        if (Flags.IsBitSet(18)) { DefaultBannedRights = buffer.Read<MyTelegram.Schema.IChatBannedRights>(); }
        if (Flags.IsBitSet(17)) { ParticipantsCount = buffer.ReadInt32(); }
        if (Flags2.IsBitSet(0)) { Usernames = buffer.Read<TVector<MyTelegram.Schema.IUsername>>(); }
        if (Flags2.IsBitSet(4)) { StoriesMaxId = buffer.ReadInt32(); }
        if (Flags2.IsBitSet(7)) { Color = buffer.Read<MyTelegram.Schema.IPeerColor>(); }
        if (Flags2.IsBitSet(8)) { ProfileColor = buffer.Read<MyTelegram.Schema.IPeerColor>(); }
        if (Flags2.IsBitSet(9)) { EmojiStatus = buffer.Read<MyTelegram.Schema.IEmojiStatus>(); }
        if (Flags2.IsBitSet(10)) { Level = buffer.ReadInt32(); }
        if (Flags2.IsBitSet(11)) { SubscriptionUntilDate = buffer.ReadInt32(); }
        if (Flags2.IsBitSet(13)) { BotVerificationIcon = buffer.ReadInt64(); }
        if (Flags2.IsBitSet(14)) { SendPaidMessagesStars = buffer.ReadInt64(); }
        if (Flags2.IsBitSet(18)) { LinkedMonoforumId = buffer.ReadInt64(); }
    }
}