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

namespace MyTelegram.Schema;

///<summary>
/// Info about bots (available bot commands, etc)
/// See <a href="https://corefork.telegram.org/constructor/botInfo" />
///</summary>
[TlObject(0x4d8a0299)]
public sealed class TBotInfo : IBotInfo
{
    public uint ConstructorId => 0x4d8a0299;
    ///<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 set, the bot has some <a href="https://corefork.telegram.org/api/bots/webapps#main-mini-app-previews">preview medias for the configured Main Mini App, see here »</a> for more info on Main Mini App preview medias.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HasPreviewMedias { get; set; }

    ///<summary>
    /// ID of the bot
    ///</summary>
    public long? UserId { get; set; }

    ///<summary>
    /// Description of the bot
    ///</summary>
    public string? Description { get; set; }

    ///<summary>
    /// Description photo
    /// See <a href="https://corefork.telegram.org/type/Photo" />
    ///</summary>
    public MyTelegram.Schema.IPhoto? DescriptionPhoto { get; set; }

    ///<summary>
    /// Description animation in MPEG4 format
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument? DescriptionDocument { get; set; }

    ///<summary>
    /// Bot commands that can be used in the chat
    ///</summary>
    public TVector<MyTelegram.Schema.IBotCommand>? Commands { get; set; }

    ///<summary>
    /// Indicates the action to execute when pressing the in-UI menu button for bots
    /// See <a href="https://corefork.telegram.org/type/BotMenuButton" />
    ///</summary>
    public MyTelegram.Schema.IBotMenuButton? MenuButton { get; set; }

    ///<summary>
    /// The HTTP link to the privacy policy of the bot. If not set, then the <code>/privacy</code> command must be used, if supported by the bot (i.e. if it's present in the <code>commands</code> vector). If it isn't supported, then <a href="https://telegram.org/privacy-tpa">https://telegram.org/privacy-tpa</a> must be opened, instead.
    ///</summary>
    public string? PrivacyPolicyUrl { get; set; }

    ///<summary>
    /// &nbsp;
    /// See <a href="https://corefork.telegram.org/type/BotAppSettings" />
    ///</summary>
    public MyTelegram.Schema.IBotAppSettings? AppSettings { get; set; }
    public MyTelegram.Schema.IBotVerifierSettings? VerifierSettings { get; set; }

    public void ComputeFlag()
    {
        if (HasPreviewMedias) { Flags = Flags.SetBit(6); }
        if (/*UserId != 0 &&*/ UserId.HasValue) { Flags = Flags.SetBit(0); }
        if (Description != null) { Flags = Flags.SetBit(1); }
        if (DescriptionPhoto != null) { Flags = Flags.SetBit(4); }
        if (DescriptionDocument != null) { Flags = Flags.SetBit(5); }
        if (Commands?.Count > 0) { Flags = Flags.SetBit(2); }
        if (MenuButton != null) { Flags = Flags.SetBit(3); }
        if (PrivacyPolicyUrl != null) { Flags = Flags.SetBit(7); }
        if (AppSettings != null) { Flags = Flags.SetBit(8); }
        if (VerifierSettings != null) { Flags = Flags.SetBit(9); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(UserId.Value); }
        if (Flags.IsBitSet(1)) { writer.Write(Description); }
        if (Flags.IsBitSet(4)) { writer.Write(DescriptionPhoto); }
        if (Flags.IsBitSet(5)) { writer.Write(DescriptionDocument); }
        if (Flags.IsBitSet(2)) { writer.Write(Commands); }
        if (Flags.IsBitSet(3)) { writer.Write(MenuButton); }
        if (Flags.IsBitSet(7)) { writer.Write(PrivacyPolicyUrl); }
        if (Flags.IsBitSet(8)) { writer.Write(AppSettings); }
        if (Flags.IsBitSet(9)) { writer.Write(VerifierSettings); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(6)) { HasPreviewMedias = true; }
        if (Flags.IsBitSet(0)) { UserId = buffer.ReadInt64(); }
        if (Flags.IsBitSet(1)) { Description = buffer.ReadString(); }
        if (Flags.IsBitSet(4)) { DescriptionPhoto = buffer.Read<MyTelegram.Schema.IPhoto>(); }
        if (Flags.IsBitSet(5)) { DescriptionDocument = buffer.Read<MyTelegram.Schema.IDocument>(); }
        if (Flags.IsBitSet(2)) { Commands = buffer.Read<TVector<MyTelegram.Schema.IBotCommand>>(); }
        if (Flags.IsBitSet(3)) { MenuButton = buffer.Read<MyTelegram.Schema.IBotMenuButton>(); }
        if (Flags.IsBitSet(7)) { PrivacyPolicyUrl = buffer.ReadString(); }
        if (Flags.IsBitSet(8)) { AppSettings = buffer.Read<MyTelegram.Schema.IBotAppSettings>(); }
        if (Flags.IsBitSet(9)) { VerifierSettings = buffer.Read<MyTelegram.Schema.IBotVerifierSettings>(); }
    }
}