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

namespace MyTelegram.Schema;

///<summary>
/// Geolocation
/// See <a href="https://corefork.telegram.org/constructor/inputBotInlineMessageMediaGeo" />
///</summary>
[TlObject(0x96929a85)]
public sealed class TInputBotInlineMessageMediaGeo : IInputBotInlineMessage
{
    public uint ConstructorId => 0x96929a85;
    ///<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
    /// See <a href="https://corefork.telegram.org/type/InputGeoPoint" />
    ///</summary>
    public MyTelegram.Schema.IInputGeoPoint GeoPoint { get; set; }

    ///<summary>
    /// For <a href="https://corefork.telegram.org/api/live-location">live locations</a>, a direction in which the location moves, in degrees; 1-360
    ///</summary>
    public int? Heading { get; set; }

    ///<summary>
    /// Validity period
    ///</summary>
    public int? Period { get; set; }

    ///<summary>
    /// For <a href="https://corefork.telegram.org/api/live-location">live locations</a>, a maximum distance to another chat member for proximity alerts, in meters (0-100000)
    ///</summary>
    public int? ProximityNotificationRadius { get; set; }

    ///<summary>
    /// Reply markup for bot/inline keyboards
    /// See <a href="https://corefork.telegram.org/type/ReplyMarkup" />
    ///</summary>
    public MyTelegram.Schema.IReplyMarkup? ReplyMarkup { get; set; }

    public void ComputeFlag()
    {
        if (/*Heading != 0 && */Heading.HasValue) { Flags = Flags.SetBit(0); }
        if (/*Period != 0 && */Period.HasValue) { Flags = Flags.SetBit(1); }
        if (/*ProximityNotificationRadius != 0 && */ProximityNotificationRadius.HasValue) { Flags = Flags.SetBit(3); }
        if (ReplyMarkup != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(GeoPoint);
        if (Flags.IsBitSet(0)) { writer.Write(Heading.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(Period.Value); }
        if (Flags.IsBitSet(3)) { writer.Write(ProximityNotificationRadius.Value); }
        if (Flags.IsBitSet(2)) { writer.Write(ReplyMarkup); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        GeoPoint = buffer.Read<MyTelegram.Schema.IInputGeoPoint>();
        if (Flags.IsBitSet(0)) { Heading = buffer.ReadInt32(); }
        if (Flags.IsBitSet(1)) { Period = buffer.ReadInt32(); }
        if (Flags.IsBitSet(3)) { ProximityNotificationRadius = buffer.ReadInt32(); }
        if (Flags.IsBitSet(2)) { ReplyMarkup = buffer.Read<MyTelegram.Schema.IReplyMarkup>(); }
    }
}