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

namespace MyTelegram.Schema;

///<summary>
/// Send a venue
/// See <a href="https://corefork.telegram.org/constructor/botInlineMessageMediaVenue" />
///</summary>
[TlObject(0x8a86659c)]
public sealed class TBotInlineMessageMediaVenue : IBotInlineMessage
{
    public uint ConstructorId => 0x8a86659c;
    ///<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>
    /// Geolocation of venue
    /// See <a href="https://corefork.telegram.org/type/GeoPoint" />
    ///</summary>
    public MyTelegram.Schema.IGeoPoint Geo { get; set; }

    ///<summary>
    /// Venue name
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// Address
    ///</summary>
    public string Address { get; set; }

    ///<summary>
    /// Venue provider: currently only "foursquare" and "gplaces" (Google Places) need to be supported
    ///</summary>
    public string Provider { get; set; }

    ///<summary>
    /// Venue ID in the provider's database
    ///</summary>
    public string VenueId { get; set; }

    ///<summary>
    /// Venue type in the provider's database
    ///</summary>
    public string VenueType { 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(Geo);
        writer.Write(Title);
        writer.Write(Address);
        writer.Write(Provider);
        writer.Write(VenueId);
        writer.Write(VenueType);
        if (Flags.IsBitSet(2)) { writer.Write(ReplyMarkup); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Geo = buffer.Read<MyTelegram.Schema.IGeoPoint>();
        Title = buffer.ReadString();
        Address = buffer.ReadString();
        Provider = buffer.ReadString();
        VenueId = buffer.ReadString();
        VenueType = buffer.ReadString();
        if (Flags.IsBitSet(2)) { ReplyMarkup = buffer.Read<MyTelegram.Schema.IReplyMarkup>(); }
    }
}