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

namespace MyTelegram.Schema.Contacts;

///<summary>
/// Get users and geochats near you, see <a href="https://corefork.telegram.org/api/nearby">here »</a> for more info.
/// <para>Possible errors</para>
/// Code Type Description
/// 406 BUSINESS_ADDRESS_ACTIVE The user is currently advertising a <a href="https://corefork.telegram.org/api/business#location">Business Location</a>, the location may only be changed (or removed) using <a href="https://corefork.telegram.org/method/account.updateBusinessLocation">account.updateBusinessLocation&nbsp;»</a>.  .
/// 400 GEO_POINT_INVALID Invalid geoposition provided.
/// 406 USERPIC_PRIVACY_REQUIRED You need to disable privacy settings for your profile picture in order to make your geolocation public.
/// 406 USERPIC_UPLOAD_REQUIRED You must have a profile picture to publish your geolocation.
/// See <a href="https://corefork.telegram.org/method/contacts.getLocated" />
///</summary>
[TlObject(0xd348bc44)]
public sealed class RequestGetLocated : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xd348bc44;
    ///<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>
    /// While the geolocation of the current user is public, clients should update it in the background every half-an-hour or so, while setting this flag. <br>Do this only if the new location is more than 1 KM away from the previous one, or if the previous location is unknown.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Background { get; set; }

    ///<summary>
    /// Geolocation
    /// See <a href="https://corefork.telegram.org/type/InputGeoPoint" />
    ///</summary>
    public MyTelegram.Schema.IInputGeoPoint GeoPoint { get; set; }

    ///<summary>
    /// If set, the geolocation of the current user will be public for the specified number of seconds; pass 0x7fffffff to disable expiry, 0 to make the current geolocation private; if the flag isn't set, no changes will be applied.
    ///</summary>
    public int? SelfExpires { get; set; }

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

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Background = true; }
        GeoPoint = buffer.Read<MyTelegram.Schema.IInputGeoPoint>();
        if (Flags.IsBitSet(0)) { SelfExpires = buffer.ReadInt32(); }
    }
}
