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

namespace MyTelegram.Schema.Updates;

///<summary>
/// There are no new updates
/// See <a href="https://corefork.telegram.org/constructor/updates.channelDifferenceEmpty" />
///</summary>
[TlObject(0x3e11affb)]
public sealed class TChannelDifferenceEmpty : IChannelDifference,IEmpty
{
    public uint ConstructorId => 0x3e11affb;
    ///<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 there are more updates that must be fetched (always false)
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Final { get; set; }

    ///<summary>
    /// The latest <a href="https://corefork.telegram.org/api/updates">PTS</a>
    ///</summary>
    public int Pts { get; set; }

    ///<summary>
    /// Clients are supposed to refetch the channel difference after timeout seconds have elapsed, if the user is <a href="https://corefork.telegram.org/api/updates#subscribing-to-updates-of-channels-supergroups">currently viewing the chat, see here »</a> for more info.
    ///</summary>
    public int? Timeout { get; set; }

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

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Final = true; }
        Pts = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Timeout = buffer.ReadInt32(); }
    }
}