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

namespace MyTelegram.Schema;

///<summary>
/// A <a href="https://corefork.telegram.org/api/saved-messages">saved message dialog</a> was pinned/unpinned
/// See <a href="https://corefork.telegram.org/constructor/updateSavedDialogPinned" />
///</summary>
[TlObject(0xaeaf9e74)]
public sealed class TUpdateSavedDialogPinned : IUpdate
{
    public uint ConstructorId => 0xaeaf9e74;
    ///<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>
    /// Whether the dialog was 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/DialogPeer" />
    ///</summary>
    public MyTelegram.Schema.IDialogPeer Peer { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
    }

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