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

namespace MyTelegram.Schema;

///<summary>
/// A button that allows the user to create and send a poll when pressed; available only in private
/// See <a href="https://corefork.telegram.org/constructor/keyboardButtonRequestPoll" />
///</summary>
[TlObject(0xbbc7515d)]
public sealed class TKeyboardButtonRequestPoll : IKeyboardButton
{
    public uint ConstructorId => 0xbbc7515d;
    ///<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>
    /// If set, only quiz polls can be sent
    /// See <a href="https://corefork.telegram.org/type/Bool" />
    ///</summary>
    public bool? Quiz { get; set; }

    ///<summary>
    /// Button text
    ///</summary>
    public string Text { get; set; }

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

    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Quiz = buffer.Read(); }
        Text = buffer.ReadString();
    }
}