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

namespace MyTelegram.Schema.E2e;


[TlObject(0x85FE42B7)]
public sealed class TPersonalEmojiNonces : IPersonal
{
    public uint ConstructorId => 0x85FE42B7;
    public int Flags { get; set; }
    public ReadOnlyMemory<byte>? SelfNonce { get; set; }
    public ReadOnlyMemory<byte>? ContactNonceHash { get; set; }
    public ReadOnlyMemory<byte>? ContactNonce { get; set; }

    public void ComputeFlag()
    {
        if (SelfNonce != null) { Flags = Flags.SetBit(0); }
        if (ContactNonceHash != null) { Flags = Flags.SetBit(1); }
        if (ContactNonce != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.WriteRawBytes(SelfNonce); }
        if (Flags.IsBitSet(1)) { writer.WriteRawBytes(ContactNonceHash); }
        if (Flags.IsBitSet(2)) { writer.WriteRawBytes(ContactNonce); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { SelfNonce = buffer.ReadInt256(); }
        if (Flags.IsBitSet(1)) { ContactNonceHash = buffer.ReadInt256(); }
        if (Flags.IsBitSet(2)) { ContactNonce = buffer.ReadInt256(); }
    }
}