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

namespace MyTelegram.Schema;

///<summary>
/// Prompts the user to select and share one or more peers with the bot using <a href="https://corefork.telegram.org/method/messages.sendBotRequestedPeer">messages.sendBotRequestedPeer</a>.
/// See <a href="https://corefork.telegram.org/constructor/inputKeyboardButtonRequestPeer" />
///</summary>
[TlObject(0xc9662d05)]
public sealed class TInputKeyboardButtonRequestPeer : IKeyboardButton
{
    public uint ConstructorId => 0xc9662d05;
    ///<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>
    /// Set this flag to request the peer's name.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool NameRequested { get; set; }

    ///<summary>
    /// Set this flag to request the peer's <code>@username</code> (if any).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool UsernameRequested { get; set; }

    ///<summary>
    /// Set this flag to request the peer's photo (if any).
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool PhotoRequested { get; set; }

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

    ///<summary>
    /// Button ID, to be passed to <a href="https://corefork.telegram.org/method/messages.sendBotRequestedPeer">messages.sendBotRequestedPeer</a>.
    ///</summary>
    public int ButtonId { get; set; }

    ///<summary>
    /// Filtering criteria to use for the peer selection list shown to the user. <br>The list should display all existing peers of the specified type, and should also offer an option for the user to create and immediately use one or more (up to <code>max_quantity</code>) peers of the specified type, if needed.
    /// See <a href="https://corefork.telegram.org/type/RequestPeerType" />
    ///</summary>
    public MyTelegram.Schema.IRequestPeerType PeerType { get; set; }

    ///<summary>
    /// Maximum number of peers that can be chosen.
    ///</summary>
    public int MaxQuantity { get; set; }

    public void ComputeFlag()
    {
        if (NameRequested) { Flags = Flags.SetBit(0); }
        if (UsernameRequested) { Flags = Flags.SetBit(1); }
        if (PhotoRequested) { Flags = Flags.SetBit(2); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Text);
        writer.Write(ButtonId);
        writer.Write(PeerType);
        writer.Write(MaxQuantity);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { NameRequested = true; }
        if (Flags.IsBitSet(1)) { UsernameRequested = true; }
        if (Flags.IsBitSet(2)) { PhotoRequested = true; }
        Text = buffer.ReadString();
        ButtonId = buffer.ReadInt32();
        PeerType = buffer.Read<MyTelegram.Schema.IRequestPeerType>();
        MaxQuantity = buffer.ReadInt32();
    }
}