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

namespace MyTelegram.Schema;

///<summary>
/// Dialog in folder
/// See <a href="https://corefork.telegram.org/constructor/dialogFolder" />
///</summary>
[TlObject(0x71bd134c)]
public sealed class TDialogFolder : IDialog
{
    public uint ConstructorId => 0x71bd134c;
    ///<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>
    /// Is this folder pinned
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Pinned { get; set; }

    ///<summary>
    /// The folder
    /// See <a href="https://corefork.telegram.org/type/Folder" />
    ///</summary>
    public MyTelegram.Schema.IFolder Folder { get; set; }

    ///<summary>
    /// Peer in folder
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer Peer { get; set; }

    ///<summary>
    /// Latest message ID of dialog
    ///</summary>
    public int TopMessage { get; set; }

    ///<summary>
    /// Number of unread muted peers in folder
    ///</summary>
    public int UnreadMutedPeersCount { get; set; }

    ///<summary>
    /// Number of unread unmuted peers in folder
    ///</summary>
    public int UnreadUnmutedPeersCount { get; set; }

    ///<summary>
    /// Number of unread messages from muted peers in folder
    ///</summary>
    public int UnreadMutedMessagesCount { get; set; }

    ///<summary>
    /// Number of unread messages from unmuted peers in folder
    ///</summary>
    public int UnreadUnmutedMessagesCount { get; set; }

    public void ComputeFlag()
    {
        if (Pinned) { Flags = Flags.SetBit(2); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Folder);
        writer.Write(Peer);
        writer.Write(TopMessage);
        writer.Write(UnreadMutedPeersCount);
        writer.Write(UnreadUnmutedPeersCount);
        writer.Write(UnreadMutedMessagesCount);
        writer.Write(UnreadUnmutedMessagesCount);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(2)) { Pinned = true; }
        Folder = buffer.Read<MyTelegram.Schema.IFolder>();
        Peer = buffer.Read<MyTelegram.Schema.IPeer>();
        TopMessage = buffer.ReadInt32();
        UnreadMutedPeersCount = buffer.ReadInt32();
        UnreadUnmutedPeersCount = buffer.ReadInt32();
        UnreadMutedMessagesCount = buffer.ReadInt32();
        UnreadUnmutedMessagesCount = buffer.ReadInt32();
    }
}