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

namespace MyTelegram.Schema.Payments;

///<summary>
/// See <a href="https://corefork.telegram.org/method/payments.getConnectedStarRefBots" />
///</summary>
[TlObject(0x5869a553)]
public sealed class RequestGetConnectedStarRefBots : IRequest<MyTelegram.Schema.Payments.IConnectedStarRefBots>
{
    public uint ConstructorId => 0x5869a553;
    ///<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/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

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

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

    ///<summary>
    /// Maximum number of results to return, <a href="https://corefork.telegram.org/api/offsets">see pagination</a>
    ///</summary>
    public int Limit { get; set; }

    public void ComputeFlag()
    {
        if (/*OffsetDate != 0 && */OffsetDate.HasValue) { Flags = Flags.SetBit(2); }
        if (OffsetLink != null) { Flags = Flags.SetBit(2); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        if (Flags.IsBitSet(2)) { writer.Write(OffsetDate.Value); }
        if (Flags.IsBitSet(2)) { writer.Write(OffsetLink); }
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(2)) { OffsetDate = buffer.ReadInt32(); }
        if (Flags.IsBitSet(2)) { OffsetLink = buffer.ReadString(); }
        Limit = buffer.ReadInt32();
    }
}
