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

namespace MyTelegram.Schema.Stats;

///<summary>
/// Load <a href="https://corefork.telegram.org/api/stats">channel statistics graph</a> asynchronously
/// <para>Possible errors</para>
/// Code Type Description
/// 400 GRAPH_EXPIRED_RELOAD This graph has expired, please obtain a new graph token.
/// 400 GRAPH_INVALID_RELOAD Invalid graph token provided, please reload the stats and provide the updated token.
/// 400 GRAPH_OUTDATED_RELOAD The graph is outdated, please get a new async token using stats.getBroadcastStats.
/// See <a href="https://corefork.telegram.org/method/stats.loadAsyncGraph" />
///</summary>
[TlObject(0x621d5fa0)]
public sealed class RequestLoadAsyncGraph : IRequest<MyTelegram.Schema.IStatsGraph>
{
    public uint ConstructorId => 0x621d5fa0;
    ///<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>
    /// Graph token from <a href="https://corefork.telegram.org/constructor/statsGraphAsync">statsGraphAsync</a> constructor
    ///</summary>
    public string Token { get; set; }

    ///<summary>
    /// Zoom value, if required
    ///</summary>
    public long? X { get; set; }

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

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

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