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

namespace MyTelegram.Schema;

///<summary>
/// Contains information about a <a href="https://corefork.telegram.org/api/bots/webapps#direct-link-mini-apps">direct link Mini App</a>.
/// See <a href="https://corefork.telegram.org/constructor/botApp" />
///</summary>
[TlObject(0x95fcd1d6)]
public sealed class TBotApp : IBotApp
{
    public uint ConstructorId => 0x95fcd1d6;
    ///<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>
    /// bot mini app ID
    ///</summary>
    public long Id { get; set; }

    ///<summary>
    /// bot mini app access hash
    ///</summary>
    public long AccessHash { get; set; }

    ///<summary>
    /// bot mini app short name, used to generate <a href="https://corefork.telegram.org/api/links#direct-mini-app-links">Direct Mini App deep links</a>.
    ///</summary>
    public string ShortName { get; set; }

    ///<summary>
    /// bot mini app title.
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// bot mini app description.
    ///</summary>
    public string Description { get; set; }

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

    ///<summary>
    /// bot mini app animation.
    /// See <a href="https://corefork.telegram.org/type/Document" />
    ///</summary>
    public MyTelegram.Schema.IDocument? Document { get; set; }

    ///<summary>
    /// Hash to pass to <a href="https://corefork.telegram.org/method/messages.getBotApp">messages.getBotApp</a>, to avoid refetching bot app info if it hasn't changed.
    ///</summary>
    public long Hash { get; set; }

    public void ComputeFlag()
    {
        if (Document != null) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Id);
        writer.Write(AccessHash);
        writer.Write(ShortName);
        writer.Write(Title);
        writer.Write(Description);
        writer.Write(Photo);
        if (Flags.IsBitSet(0)) { writer.Write(Document); }
        writer.Write(Hash);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Id = buffer.ReadInt64();
        AccessHash = buffer.ReadInt64();
        ShortName = buffer.ReadString();
        Title = buffer.ReadString();
        Description = buffer.ReadString();
        Photo = buffer.Read<MyTelegram.Schema.IPhoto>();
        if (Flags.IsBitSet(0)) { Document = buffer.Read<MyTelegram.Schema.IDocument>(); }
        Hash = buffer.ReadInt64();
    }
}