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

namespace MyTelegram.Schema.Bots;

///<summary>
/// See <a href="https://corefork.telegram.org/method/bots.updateStarRefProgram" />
///</summary>
[TlObject(0x778b5ab3)]
public sealed class RequestUpdateStarRefProgram : IRequest<MyTelegram.Schema.IStarRefProgram>
{
    public uint ConstructorId => 0x778b5ab3;
    ///<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/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser Bot { get; set; }

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

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

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

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Bot = buffer.Read<MyTelegram.Schema.IInputUser>();
        CommissionPermille = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { DurationMonths = buffer.ReadInt32(); }
    }
}
