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

namespace MyTelegram.Schema.Help;

///<summary>
/// Deep link info, see <a href="https://corefork.telegram.org/api/links#unsupported-links">the here for more details</a>
/// See <a href="https://corefork.telegram.org/constructor/help.deepLinkInfo" />
///</summary>
[TlObject(0x6a4ee832)]
public sealed class TDeepLinkInfo : IDeepLinkInfo
{
    public uint ConstructorId => 0x6a4ee832;
    ///<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>
    /// An update of the app is required to parse this link
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool UpdateApp { get; set; }

    ///<summary>
    /// Message to show to the user
    ///</summary>
    public string Message { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/entities">Message entities for styled text</a>
    ///</summary>
    public TVector<MyTelegram.Schema.IMessageEntity>? Entities { get; set; }

    public void ComputeFlag()
    {
        if (UpdateApp) { Flags = Flags.SetBit(0); }
        if (Entities?.Count > 0) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Message);
        if (Flags.IsBitSet(1)) { writer.Write(Entities); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { UpdateApp = true; }
        Message = buffer.ReadString();
        if (Flags.IsBitSet(1)) { Entities = buffer.Read<TVector<MyTelegram.Schema.IMessageEntity>>(); }
    }
}