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

namespace MyTelegram.Schema;

///<summary>
/// Represents a geolocation tag attached to a <a href="https://corefork.telegram.org/api/stories">story</a>.
/// See <a href="https://corefork.telegram.org/constructor/mediaAreaGeoPoint" />
///</summary>
[TlObject(0xcad5452d)]
public sealed class TMediaAreaGeoPoint : IMediaArea
{
    public uint ConstructorId => 0xcad5452d;
    ///<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>
    /// The size and position of the media area corresponding to the location sticker on top of the story media.
    /// See <a href="https://corefork.telegram.org/type/MediaAreaCoordinates" />
    ///</summary>
    public MyTelegram.Schema.IMediaAreaCoordinates Coordinates { get; set; }

    ///<summary>
    /// Coordinates of the geolocation tag.
    /// See <a href="https://corefork.telegram.org/type/GeoPoint" />
    ///</summary>
    public MyTelegram.Schema.IGeoPoint Geo { get; set; }

    ///<summary>
    /// Optional textual representation of the address.
    /// See <a href="https://corefork.telegram.org/type/GeoPointAddress" />
    ///</summary>
    public MyTelegram.Schema.IGeoPointAddress? Address { get; set; }

    public void ComputeFlag()
    {
        if (Address != null) { Flags = Flags.SetBit(0); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Coordinates);
        writer.Write(Geo);
        if (Flags.IsBitSet(0)) { writer.Write(Address); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Coordinates = buffer.Read<MyTelegram.Schema.IMediaAreaCoordinates>();
        Geo = buffer.Read<MyTelegram.Schema.IGeoPoint>();
        if (Flags.IsBitSet(0)) { Address = buffer.Read<MyTelegram.Schema.IGeoPointAddress>(); }
    }
}