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

namespace MyTelegram.Schema;

///<summary>
/// Banned/kicked user
/// See <a href="https://corefork.telegram.org/constructor/channelParticipantBanned" />
///</summary>
[TlObject(0x6df8014e)]
public sealed class TChannelParticipantBanned : IChannelParticipant
{
    public uint ConstructorId => 0x6df8014e;
    ///<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 user has left the group
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Left { get; set; }

    ///<summary>
    /// The banned peer
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer Peer { get; set; }

    ///<summary>
    /// User was kicked by the specified admin
    ///</summary>
    public long KickedBy { get; set; }

    ///<summary>
    /// When did the user join the group
    ///</summary>
    public int Date { get; set; }

    ///<summary>
    /// Banned <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; }

    public void ComputeFlag()
    {
        if (Left) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(KickedBy);
        writer.Write(Date);
        writer.Write(BannedRights);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Left = true; }
        Peer = buffer.Read<MyTelegram.Schema.IPeer>();
        KickedBy = buffer.ReadInt64();
        Date = buffer.ReadInt32();
        BannedRights = buffer.Read<MyTelegram.Schema.IChatBannedRights>();
    }
}