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

namespace MyTelegram.Schema;

///<summary>
/// Send a contact
/// See <a href="https://corefork.telegram.org/constructor/botInlineMessageMediaContact" />
///</summary>
[TlObject(0x18d1cdc2)]
public sealed class TBotInlineMessageMediaContact : IBotInlineMessage
{
    public uint ConstructorId => 0x18d1cdc2;
    ///<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>
    /// Phone number
    ///</summary>
    public string PhoneNumber { get; set; }

    ///<summary>
    /// First name
    ///</summary>
    public string FirstName { get; set; }

    ///<summary>
    /// Last name
    ///</summary>
    public string LastName { get; set; }

    ///<summary>
    /// VCard info
    ///</summary>
    public string Vcard { get; set; }

    ///<summary>
    /// Inline keyboard
    /// See <a href="https://corefork.telegram.org/type/ReplyMarkup" />
    ///</summary>
    public MyTelegram.Schema.IReplyMarkup? ReplyMarkup { get; set; }

    public void ComputeFlag()
    {
        if (ReplyMarkup != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(PhoneNumber);
        writer.Write(FirstName);
        writer.Write(LastName);
        writer.Write(Vcard);
        if (Flags.IsBitSet(2)) { writer.Write(ReplyMarkup); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        PhoneNumber = buffer.ReadString();
        FirstName = buffer.ReadString();
        LastName = buffer.ReadString();
        Vcard = buffer.ReadString();
        if (Flags.IsBitSet(2)) { ReplyMarkup = buffer.Read<MyTelegram.Schema.IReplyMarkup>(); }
    }
}