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

namespace MyTelegram.Schema;

///<summary>
/// See <a href="https://corefork.telegram.org/constructor/monoForumDialog" />
///</summary>
[TlObject(0x64407ea7)]
public sealed class TMonoForumDialog : ISavedDialog
{
    public uint ConstructorId => 0x64407ea7;
    public int Flags { get; set; }
    public bool UnreadMark { get; set; }
    public bool NopaidMessagesException { get; set; }
    public MyTelegram.Schema.IPeer Peer { get; set; }
    public int TopMessage { get; set; }
    public int ReadInboxMaxId { get; set; }
    public int ReadOutboxMaxId { get; set; }
    public int UnreadCount { get; set; }
    public int UnreadReactionsCount { get; set; }
    public MyTelegram.Schema.IDraftMessage? Draft { get; set; }

    public void ComputeFlag()
    {
        if (UnreadMark) { Flags = Flags.SetBit(3); }
        if (NopaidMessagesException) { Flags = Flags.SetBit(4); }
        if (Draft != null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(TopMessage);
        writer.Write(ReadInboxMaxId);
        writer.Write(ReadOutboxMaxId);
        writer.Write(UnreadCount);
        writer.Write(UnreadReactionsCount);
        if (Flags.IsBitSet(1)) { writer.Write(Draft); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(3)) { UnreadMark = true; }
        if (Flags.IsBitSet(4)) { NopaidMessagesException = true; }
        Peer = buffer.Read<MyTelegram.Schema.IPeer>();
        TopMessage = buffer.ReadInt32();
        ReadInboxMaxId = buffer.ReadInt32();
        ReadOutboxMaxId = buffer.ReadInt32();
        UnreadCount = buffer.ReadInt32();
        UnreadReactionsCount = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Draft = buffer.Read<MyTelegram.Schema.IDraftMessage>(); }
    }
}