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

namespace MyTelegram.Schema;

///<summary>
/// Generic result
/// See <a href="https://corefork.telegram.org/constructor/botInlineResult" />
///</summary>
[TlObject(0x11965f3a)]
public sealed class TBotInlineResult : IBotInlineResult
{
    public uint ConstructorId => 0x11965f3a;
    ///<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>
    /// Result ID
    ///</summary>
    public string Id { get; set; }

    ///<summary>
    /// Result type (see <a href="https://corefork.telegram.org/bots/api#inlinequeryresult">bot API docs</a>)
    ///</summary>
    public string Type { get; set; }

    ///<summary>
    /// Result title
    ///</summary>
    public string? Title { get; set; }

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

    ///<summary>
    /// URL of article or webpage
    ///</summary>
    public string? Url { get; set; }

    ///<summary>
    /// Thumbnail for the result
    /// See <a href="https://corefork.telegram.org/type/WebDocument" />
    ///</summary>
    public MyTelegram.Schema.IWebDocument? Thumb { get; set; }

    ///<summary>
    /// Content of the result
    /// See <a href="https://corefork.telegram.org/type/WebDocument" />
    ///</summary>
    public MyTelegram.Schema.IWebDocument? Content { get; set; }

    ///<summary>
    /// Message to send
    /// See <a href="https://corefork.telegram.org/type/BotInlineMessage" />
    ///</summary>
    public MyTelegram.Schema.IBotInlineMessage SendMessage { get; set; }

    public void ComputeFlag()
    {
        if (Title != null) { Flags = Flags.SetBit(1); }
        if (Description != null) { Flags = Flags.SetBit(2); }
        if (Url != null) { Flags = Flags.SetBit(3); }
        if (Thumb != null) { Flags = Flags.SetBit(4); }
        if (Content != null) { Flags = Flags.SetBit(5); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
        writer.Write(Type);
        if (Flags.IsBitSet(1)) { writer.Write(Title); }
        if (Flags.IsBitSet(2)) { writer.Write(Description); }
        if (Flags.IsBitSet(3)) { writer.Write(Url); }
        if (Flags.IsBitSet(4)) { writer.Write(Thumb); }
        if (Flags.IsBitSet(5)) { writer.Write(Content); }
        writer.Write(SendMessage);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Id = buffer.ReadString();
        Type = buffer.ReadString();
        if (Flags.IsBitSet(1)) { Title = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { Description = buffer.ReadString(); }
        if (Flags.IsBitSet(3)) { Url = buffer.ReadString(); }
        if (Flags.IsBitSet(4)) { Thumb = buffer.Read<MyTelegram.Schema.IWebDocument>(); }
        if (Flags.IsBitSet(5)) { Content = buffer.Read<MyTelegram.Schema.IWebDocument>(); }
        SendMessage = buffer.Read<MyTelegram.Schema.IBotInlineMessage>();
    }
}