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

namespace MyTelegram.Schema.Bots;

///<summary>
/// Set localized name, about text and description of a bot (or of the current account, if called by a bot).
/// <para>Possible errors</para>
/// Code Type Description
/// 400 USER_BOT_INVALID User accounts must provide the <code>bot</code> method parameter when calling this method. If there is no such method parameter, this method can only be invoked by bot accounts.
/// See <a href="https://corefork.telegram.org/method/bots.setBotInfo" />
///</summary>
[TlObject(0x10cf3123)]
public sealed class RequestSetBotInfo : IRequest<IBool>
{
    public uint ConstructorId => 0x10cf3123;
    ///<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>
    /// If called by a user, <strong>must</strong> contain the peer of a bot we own.
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser? Bot { get; set; }

    ///<summary>
    /// Language code, if left empty update the fallback about text and description
    ///</summary>
    public string LangCode { get; set; }

    ///<summary>
    /// New bot name
    ///</summary>
    public string? Name { get; set; }

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

    ///<summary>
    /// New description
    ///</summary>
    public string? Description { get; set; }

    public void ComputeFlag()
    {
        if (Bot != null) { Flags = Flags.SetBit(2); }
        if (Name != null) { Flags = Flags.SetBit(3); }
        if (About != null) { Flags = Flags.SetBit(0); }
        if (Description != null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(2)) { writer.Write(Bot); }
        writer.Write(LangCode);
        if (Flags.IsBitSet(3)) { writer.Write(Name); }
        if (Flags.IsBitSet(0)) { writer.Write(About); }
        if (Flags.IsBitSet(1)) { writer.Write(Description); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(2)) { Bot = buffer.Read<MyTelegram.Schema.IInputUser>(); }
        LangCode = buffer.ReadString();
        if (Flags.IsBitSet(3)) { Name = buffer.ReadString(); }
        if (Flags.IsBitSet(0)) { About = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { Description = buffer.ReadString(); }
    }
}
