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

namespace MyTelegram.Schema.E2e;


[TlObject(0xD6B679E6)]
public sealed class TStateProof : IStateProof
{
    public uint ConstructorId => 0xD6B679E6;
    public int Flags { get; set; }
    public ReadOnlyMemory<byte> KvHash { get; set; }
    public MyTelegram.Schema.E2e.IGroupState? GroupState { get; set; }
    public MyTelegram.Schema.E2e.ISharedKey? SharedKey { get; set; }

    public void ComputeFlag()
    {
        if (GroupState != null) { Flags = Flags.SetBit(0); }
        if (SharedKey != null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.WriteRawBytes(KvHash);
        if (Flags.IsBitSet(0)) { writer.Write(GroupState); }
        if (Flags.IsBitSet(1)) { writer.Write(SharedKey); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        KvHash = buffer.ReadInt256();
        if (Flags.IsBitSet(0)) { GroupState = buffer.Read<MyTelegram.Schema.E2e.IGroupState>(); }
        if (Flags.IsBitSet(1)) { SharedKey = buffer.Read<MyTelegram.Schema.E2e.ISharedKey>(); }
    }
}