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

namespace MyTelegram.Schema;

///<summary>
/// Button to force a user to switch to inline mode: pressing the button will prompt the user to select one of their chats, open that chat and insert the bot's username and the specified inline query in the input field.
/// See <a href="https://corefork.telegram.org/constructor/keyboardButtonSwitchInline" />
///</summary>
[TlObject(0x93b9fbb5)]
public sealed class TKeyboardButtonSwitchInline : IKeyboardButton
{
    public uint ConstructorId => 0x93b9fbb5;
    ///<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, pressing the button will insert the bot's username and the specified inline <code>query</code> in the current chat's input field.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool SamePeer { get; set; }

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

    ///<summary>
    /// The inline query to use
    ///</summary>
    public string Query { get; set; }

    ///<summary>
    /// Filter to use when selecting chats.
    ///</summary>
    public TVector<MyTelegram.Schema.IInlineQueryPeerType>? PeerTypes { get; set; }

    public void ComputeFlag()
    {
        if (SamePeer) { Flags = Flags.SetBit(0); }
        if (PeerTypes?.Count > 0) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Text);
        writer.Write(Query);
        if (Flags.IsBitSet(1)) { writer.Write(PeerTypes); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { SamePeer = true; }
        Text = buffer.ReadString();
        Query = buffer.ReadString();
        if (Flags.IsBitSet(1)) { PeerTypes = buffer.Read<TVector<MyTelegram.Schema.IInlineQueryPeerType>>(); }
    }
}