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

namespace MyTelegram.Schema;

///<summary>
/// Contains info about a <a href="https://corefork.telegram.org/api/business#business-chat-links">business chat deep link »</a> to be created by the current account.
/// See <a href="https://corefork.telegram.org/constructor/inputBusinessChatLink" />
///</summary>
[TlObject(0x11679fa7)]
public sealed class TInputBusinessChatLink : IInputBusinessChatLink
{
    public uint ConstructorId => 0x11679fa7;
    ///<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>
    /// Message to pre-fill in the message input field.
    ///</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; }

    ///<summary>
    /// Human-readable name of the link, to simplify management in the UI (only visible to the creator of the link).
    ///</summary>
    public string? Title { get; set; }

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

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

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