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

namespace MyTelegram.Schema.Account;

///<summary>
/// Updates user profile.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 ABOUT_TOO_LONG About string too long.
/// 400 FIRSTNAME_INVALID The first name is invalid.
/// See <a href="https://corefork.telegram.org/method/account.updateProfile" />
///</summary>
[TlObject(0x78515775)]
public sealed class RequestUpdateProfile : IRequest<MyTelegram.Schema.IUser>
{
    public uint ConstructorId => 0x78515775;
    ///<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>
    /// New user first name
    ///</summary>
    public string? FirstName { get; set; }

    ///<summary>
    /// New user last name
    ///</summary>
    public string? LastName { get; set; }

    ///<summary>
    /// New bio
    ///</summary>
    public string? About { get; set; }

    public void ComputeFlag()
    {
        if (FirstName != null) { Flags = Flags.SetBit(0); }
        if (LastName != null) { Flags = Flags.SetBit(1); }
        if (About != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(FirstName); }
        if (Flags.IsBitSet(1)) { writer.Write(LastName); }
        if (Flags.IsBitSet(2)) { writer.Write(About); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { FirstName = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { LastName = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { About = buffer.ReadString(); }
    }
}
