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

namespace MyTelegram.Schema.Payments;

///<summary>
/// <a href="https://corefork.telegram.org/api/stars">Star revenue statistics, see here »</a> for more info.Note that all balances and currency amounts and graph values are in Stars.
/// See <a href="https://corefork.telegram.org/constructor/payments.starsRevenueStats" />
///</summary>
[TlObject(0x6c207376)]
public sealed class TStarsRevenueStats : IStarsRevenueStats
{
    public uint ConstructorId => 0x6c207376;
    public int Flags { get; set; }
    public MyTelegram.Schema.IStatsGraph? TopHoursGraph { get; set; }

    ///<summary>
    /// Star revenue graph (number of earned stars)
    /// See <a href="https://corefork.telegram.org/type/StatsGraph" />
    ///</summary>
    public MyTelegram.Schema.IStatsGraph RevenueGraph { get; set; }

    ///<summary>
    /// Current balance, current withdrawable balance and overall earned Telegram Stars
    /// See <a href="https://corefork.telegram.org/type/StarsRevenueStatus" />
    ///</summary>
    public MyTelegram.Schema.IStarsRevenueStatus Status { get; set; }

    ///<summary>
    /// Current conversion rate of Telegram Stars to USD
    ///</summary>
    public double UsdRate { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(TopHoursGraph); }
        writer.Write(RevenueGraph);
        writer.Write(Status);
        writer.Write(UsdRate);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { TopHoursGraph = buffer.Read<MyTelegram.Schema.IStatsGraph>(); }
        RevenueGraph = buffer.Read<MyTelegram.Schema.IStatsGraph>();
        Status = buffer.Read<MyTelegram.Schema.IStarsRevenueStatus>();
        UsdRate = buffer.ReadDouble();
    }
}