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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Get poll results for non-anonymous polls
/// <para>Possible errors</para>
/// Code Type Description
/// 403 BROADCAST_FORBIDDEN Channel poll voters and reactions cannot be fetched to prevent deanonymization.
/// 400 MSG_ID_INVALID Invalid message ID provided.
/// 403 POLL_VOTE_REQUIRED Cast a vote in the poll before calling this method.
/// See <a href="https://corefork.telegram.org/method/messages.getPollVotes" />
///</summary>
[TlObject(0xb86e380e)]
public sealed class RequestGetPollVotes : IRequest<MyTelegram.Schema.Messages.IVotesList>
{
    public uint ConstructorId => 0xb86e380e;
    ///<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>
    /// Chat where the poll was sent
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// Message ID
    ///</summary>
    public int Id { get; set; }

    ///<summary>
    /// Get only results for the specified poll <code>option</code>
    ///</summary>
    public ReadOnlyMemory<byte>? Option { get; set; }

    ///<summary>
    /// Offset for results, taken from the <code>next_offset</code> field of <a href="https://corefork.telegram.org/constructor/messages.votesList">messages.votesList</a>, initially an empty string. <br>Note: if no more results are available, the method call will return an empty <code>next_offset</code>; thus, avoid providing the <code>next_offset</code> returned in <a href="https://corefork.telegram.org/constructor/messages.votesList">messages.votesList</a> if it is empty, to avoid an infinite loop.
    ///</summary>
    public string? Offset { get; set; }

    ///<summary>
    /// Number of results to return
    ///</summary>
    public int Limit { get; set; }

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

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(Id);
        if (Flags.IsBitSet(0)) { writer.Write(Option); }
        if (Flags.IsBitSet(1)) { writer.Write(Offset); }
        writer.Write(Limit);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        Id = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Option = buffer.ReadBytes(); }
        if (Flags.IsBitSet(1)) { Offset = buffer.ReadString(); }
        Limit = buffer.ReadInt32();
    }
}
