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

namespace MyTelegram.Schema;

///<summary>
/// Document (media of any type except for photos)
/// See <a href="https://corefork.telegram.org/constructor/inputBotInlineResultDocument" />
///</summary>
[TlObject(0xfff8fdc4)]
public sealed class TInputBotInlineResultDocument : IInputBotInlineResult
{
    public uint ConstructorId => 0xfff8fdc4;
    ///<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>
    /// Document to send
    /// See <a href="https://corefork.telegram.org/type/InputDocument" />
    ///</summary>
    public MyTelegram.Schema.IInputDocument Document { get; set; }

    ///<summary>
    /// Message to send when the result is selected
    /// See <a href="https://corefork.telegram.org/type/InputBotInlineMessage" />
    ///</summary>
    public MyTelegram.Schema.IInputBotInlineMessage SendMessage { get; set; }

    public void ComputeFlag()
    {
        if (Title != null) { Flags = Flags.SetBit(1); }
        if (Description != null) { Flags = Flags.SetBit(2); }

    }

    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); }
        writer.Write(Document);
        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(); }
        Document = buffer.Read<MyTelegram.Schema.IInputDocument>();
        SendMessage = buffer.Read<MyTelegram.Schema.IInputBotInlineMessage>();
    }
}