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

namespace MyTelegram.Schema;

///<summary>
/// Represents a <a href="https://corefork.telegram.org/api/saved-messages">saved dialog »</a>.
/// See <a href="https://corefork.telegram.org/constructor/savedDialog" />
///</summary>
[TlObject(0xbd87cb6c)]
public sealed class TSavedDialog : ISavedDialog
{
    public uint ConstructorId => 0xbd87cb6c;
    ///<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 the dialog pinned
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Pinned { get; set; }

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

    ///<summary>
    /// The latest message ID
    ///</summary>
    public int TopMessage { 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(Peer);
        writer.Write(TopMessage);
    }

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