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

namespace MyTelegram.Schema.Contacts;

///<summary>
/// Resolve a @username to get peer info
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CONNECTION_LAYER_INVALID Layer invalid.
/// 400 USERNAME_INVALID The provided username is not valid.
/// 400 USERNAME_NOT_OCCUPIED The provided username is not occupied.
/// See <a href="https://corefork.telegram.org/method/contacts.resolveUsername" />
///</summary>
[TlObject(0x725afbbc)]
public sealed class RequestResolveUsername : IRequest<MyTelegram.Schema.Contacts.IResolvedPeer>
{
    public uint ConstructorId => 0x725afbbc;
    ///<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>
    /// @username to resolve
    ///</summary>
    public string Username { get; set; }

    ///<summary>
    /// &nbsp;
    ///</summary>
    public string? Referer { get; set; }

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

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Username = buffer.ReadString();
        if (Flags.IsBitSet(0)) { Referer = buffer.ReadString(); }
    }
}
