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

namespace MyTelegram.Schema;

///<summary>
/// <a href="https://corefork.telegram.org/api/stats">Channel statistics graph</a>
/// See <a href="https://corefork.telegram.org/constructor/statsGraph" />
///</summary>
[TlObject(0x8ea464b6)]
public sealed class TStatsGraph : IStatsGraph
{
    public uint ConstructorId => 0x8ea464b6;
    ///<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>
    /// Statistics data
    /// See <a href="https://corefork.telegram.org/type/DataJSON" />
    ///</summary>
    public MyTelegram.Schema.IDataJSON Json { get; set; }

    ///<summary>
    /// Zoom token
    ///</summary>
    public string? ZoomToken { get; set; }

    public void ComputeFlag()
    {
        if (ZoomToken != null) { Flags = Flags.SetBit(0); }
    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Json = buffer.Read<MyTelegram.Schema.IDataJSON>();
        if (Flags.IsBitSet(0)) { ZoomToken = buffer.ReadString(); }
    }
}