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

namespace MyTelegram.Schema;

///<summary>
/// Represents the rights of a normal user in a <a href="https://corefork.telegram.org/api/channel">supergroup/channel/chat</a>. In this case, the flags are inverted: if set, a flag <strong>does not allow</strong> a user to do X.
/// See <a href="https://corefork.telegram.org/constructor/chatBannedRights" />
///</summary>
[TlObject(0x9f120418)]
public sealed class TChatBannedRights : IChatBannedRights
{
    public uint ConstructorId => 0x9f120418;
    ///<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>
    /// If set, does not allow a user to view messages in a <a href="https://corefork.telegram.org/api/channel">supergroup/channel/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ViewMessages { get; set; }

    ///<summary>
    /// If set, does not allow a user to send messages in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendMessages { get; set; }

    ///<summary>
    /// If set, does not allow a user to send any media in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendMedia { get; set; }

    ///<summary>
    /// If set, does not allow a user to send stickers in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendStickers { get; set; }

    ///<summary>
    /// If set, does not allow a user to send gifs in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendGifs { get; set; }

    ///<summary>
    /// If set, does not allow a user to send games in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendGames { get; set; }

    ///<summary>
    /// If set, does not allow a user to use inline bots in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendInline { get; set; }

    ///<summary>
    /// If set, does not allow a user to embed links in the messages of a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool EmbedLinks { get; set; }

    ///<summary>
    /// If set, does not allow a user to send polls in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendPolls { get; set; }

    ///<summary>
    /// If set, does not allow any user to change the description of a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ChangeInfo { get; set; }

    ///<summary>
    /// If set, does not allow any user to invite users in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool InviteUsers { get; set; }

    ///<summary>
    /// If set, does not allow any user to pin messages in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool PinMessages { get; set; }

    ///<summary>
    /// If set, does not allow any user to create, delete or modify <a href="https://corefork.telegram.org/api/forum#forum-topics">forum topics »</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ManageTopics { get; set; }

    ///<summary>
    /// If set, does not allow a user to send photos in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendPhotos { get; set; }

    ///<summary>
    /// If set, does not allow a user to send videos in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendVideos { get; set; }

    ///<summary>
    /// If set, does not allow a user to send round videos in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendRoundvideos { get; set; }

    ///<summary>
    /// If set, does not allow a user to send audio files in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendAudios { get; set; }

    ///<summary>
    /// If set, does not allow a user to send voice messages in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendVoices { get; set; }

    ///<summary>
    /// If set, does not allow a user to send documents in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendDocs { get; set; }

    ///<summary>
    /// If set, does not allow a user to send text messages in a <a href="https://corefork.telegram.org/api/channel">supergroup/chat</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SendPlain { get; set; }

    ///<summary>
    /// Validity of said permissions (it is considered forever any value less then 30 seconds or more then 366 days).
    ///</summary>
    public int UntilDate { get; set; }

    public void ComputeFlag()
    {
        if (ViewMessages) { Flags = Flags.SetBit(0); }
        if (SendMessages) { Flags = Flags.SetBit(1); }
        if (SendMedia) { Flags = Flags.SetBit(2); }
        if (SendStickers) { Flags = Flags.SetBit(3); }
        if (SendGifs) { Flags = Flags.SetBit(4); }
        if (SendGames) { Flags = Flags.SetBit(5); }
        if (SendInline) { Flags = Flags.SetBit(6); }
        if (EmbedLinks) { Flags = Flags.SetBit(7); }
        if (SendPolls) { Flags = Flags.SetBit(8); }
        if (ChangeInfo) { Flags = Flags.SetBit(10); }
        if (InviteUsers) { Flags = Flags.SetBit(15); }
        if (PinMessages) { Flags = Flags.SetBit(17); }
        if (ManageTopics) { Flags = Flags.SetBit(18); }
        if (SendPhotos) { Flags = Flags.SetBit(19); }
        if (SendVideos) { Flags = Flags.SetBit(20); }
        if (SendRoundvideos) { Flags = Flags.SetBit(21); }
        if (SendAudios) { Flags = Flags.SetBit(22); }
        if (SendVoices) { Flags = Flags.SetBit(23); }
        if (SendDocs) { Flags = Flags.SetBit(24); }
        if (SendPlain) { Flags = Flags.SetBit(25); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(UntilDate);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { ViewMessages = true; }
        if (Flags.IsBitSet(1)) { SendMessages = true; }
        if (Flags.IsBitSet(2)) { SendMedia = true; }
        if (Flags.IsBitSet(3)) { SendStickers = true; }
        if (Flags.IsBitSet(4)) { SendGifs = true; }
        if (Flags.IsBitSet(5)) { SendGames = true; }
        if (Flags.IsBitSet(6)) { SendInline = true; }
        if (Flags.IsBitSet(7)) { EmbedLinks = true; }
        if (Flags.IsBitSet(8)) { SendPolls = true; }
        if (Flags.IsBitSet(10)) { ChangeInfo = true; }
        if (Flags.IsBitSet(15)) { InviteUsers = true; }
        if (Flags.IsBitSet(17)) { PinMessages = true; }
        if (Flags.IsBitSet(18)) { ManageTopics = true; }
        if (Flags.IsBitSet(19)) { SendPhotos = true; }
        if (Flags.IsBitSet(20)) { SendVideos = true; }
        if (Flags.IsBitSet(21)) { SendRoundvideos = true; }
        if (Flags.IsBitSet(22)) { SendAudios = true; }
        if (Flags.IsBitSet(23)) { SendVoices = true; }
        if (Flags.IsBitSet(24)) { SendDocs = true; }
        if (Flags.IsBitSet(25)) { SendPlain = true; }
        UntilDate = buffer.ReadInt32();
    }
}