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

namespace MyTelegram.Schema.Contacts;

///<summary>
/// Add an existing telegram user as contact.Use <a href="https://corefork.telegram.org/method/contacts.importContacts">contacts.importContacts</a> to add contacts by phone number, without knowing their Telegram ID.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 400 CONTACT_ID_INVALID The provided contact ID is invalid.
/// 400 CONTACT_NAME_EMPTY Contact name empty.
/// 400 MSG_ID_INVALID Invalid message ID provided.
/// See <a href="https://corefork.telegram.org/method/contacts.addContact" />
///</summary>
[TlObject(0xe8f463d0)]
public sealed class RequestAddContact : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xe8f463d0;
    ///<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>
    /// Allow the other user to see our phone number?
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool AddPhonePrivacyException { get; set; }

    ///<summary>
    /// Telegram ID of the other user
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser Id { get; set; }

    ///<summary>
    /// First name
    ///</summary>
    public string FirstName { get; set; }

    ///<summary>
    /// Last name
    ///</summary>
    public string LastName { get; set; }

    ///<summary>
    /// User's phone number, may be omitted to simply add the user to the contact list, without a phone number.
    ///</summary>
    public string Phone { get; set; }

    public void ComputeFlag()
    {
        if (AddPhonePrivacyException) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
        writer.Write(FirstName);
        writer.Write(LastName);
        writer.Write(Phone);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { AddPhonePrivacyException = true; }
        Id = buffer.Read<MyTelegram.Schema.IInputUser>();
        FirstName = buffer.ReadString();
        LastName = buffer.ReadString();
        Phone = buffer.ReadString();
    }
}
