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

namespace MyTelegram.Schema.E2e;


[TlObject(0x18F3971F)]
public sealed class TGroupParticipant : IGroupParticipant
{
    public uint ConstructorId => 0x18F3971F;
    public long UserId { get; set; }
    public ReadOnlyMemory<byte> PublicKey { get; set; }
    public int Flags { get; set; }
    public bool AddUsers { get; set; }
    public bool RemoveUsers { get; set; }
    public int Version { get; set; }

    public void ComputeFlag()
    {
        if (AddUsers) { Flags = Flags.SetBit(0); }
        if (RemoveUsers) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(UserId);
        writer.WriteRawBytes(PublicKey);
        writer.Write(Flags);
        writer.Write(Version);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        UserId = buffer.ReadInt64();
        PublicKey = buffer.ReadInt256();
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { AddUsers = true; }
        if (Flags.IsBitSet(1)) { RemoveUsers = true; }
        Version = buffer.ReadInt32();
    }
}