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

namespace MyTelegram.Schema;

///<summary>
/// Defines a GeoPoint by its coordinates.
/// See <a href="https://corefork.telegram.org/constructor/inputGeoPoint" />
///</summary>
[TlObject(0x48222faf)]
public sealed class TInputGeoPoint : IInputGeoPoint
{
    public uint ConstructorId => 0x48222faf;
    ///<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>
    /// Latitude
    ///</summary>
    public double Lat { get; set; }

    ///<summary>
    /// Longitude
    ///</summary>
    public double Long { get; set; }

    ///<summary>
    /// The estimated horizontal accuracy of the location, in meters; as defined by the sender.
    ///</summary>
    public int? AccuracyRadius { get; set; }

    public void ComputeFlag()
    {
        if (/*AccuracyRadius != 0 && */AccuracyRadius.HasValue) { Flags = Flags.SetBit(0); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Lat);
        writer.Write(Long);
        if (Flags.IsBitSet(0)) { writer.Write(AccuracyRadius.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Lat = buffer.ReadDouble();
        Long = buffer.ReadDouble();
        if (Flags.IsBitSet(0)) { AccuracyRadius = buffer.ReadInt32(); }
    }
}