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

namespace MyTelegram.Schema;

///<summary>
/// See <a href="https://corefork.telegram.org/constructor/connectedBotStarRef" />
///</summary>
[TlObject(0x19a13f71)]
public sealed class TConnectedBotStarRef : IConnectedBotStarRef
{
    public uint ConstructorId => 0x19a13f71;
    ///<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>
    /// &nbsp;
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Revoked { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public string Url { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public int Date { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public long BotId { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public int CommissionPermille { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public int? DurationMonths { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public long Participants { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public long Revenue { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Url);
        writer.Write(Date);
        writer.Write(BotId);
        writer.Write(CommissionPermille);
        if (Flags.IsBitSet(0)) { writer.Write(DurationMonths.Value); }
        writer.Write(Participants);
        writer.Write(Revenue);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Revoked = true; }
        Url = buffer.ReadString();
        Date = buffer.ReadInt32();
        BotId = buffer.ReadInt64();
        CommissionPermille = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { DurationMonths = buffer.ReadInt32(); }
        Participants = buffer.ReadInt64();
        Revenue = buffer.ReadInt64();
    }
}