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

namespace MyTelegram.Schema;

///<summary>
/// Empty constructor, non-existent message.
/// See <a href="https://corefork.telegram.org/constructor/messageEmpty" />
///</summary>
[TlObject(0x90a6ca84)]
public sealed class TMessageEmpty : IMessage,IEmpty
{
    public uint ConstructorId => 0x90a6ca84;
    ///<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>
    /// Message identifier
    ///</summary>
    public int Id { get; set; }

    ///<summary>
    /// Peer ID, the chat where this message was sent
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer? PeerId { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
        if (Flags.IsBitSet(0)) { writer.Write(PeerId); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Id = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { PeerId = buffer.Read<MyTelegram.Schema.IPeer>(); }
    }
}