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

namespace MyTelegram.Schema;

///<summary>
/// The preview of the webpage hasn't changed
/// See <a href="https://corefork.telegram.org/constructor/webPageNotModified" />
///</summary>
[TlObject(0x7311ca11)]
public sealed class TWebPageNotModified : IWebPage
{
    public uint ConstructorId => 0x7311ca11;
    ///<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>
    /// Page view count
    ///</summary>
    public int? CachedPageViews { get; set; }

    public void ComputeFlag()
    {
        if (/*CachedPageViews != 0 && */CachedPageViews.HasValue) { Flags = Flags.SetBit(0); }
    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { CachedPageViews = buffer.ReadInt32(); }
    }
}