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

namespace MyTelegram.Schema.Help;

///<summary>
/// MTProxy/Public Service Announcement information
/// See <a href="https://corefork.telegram.org/constructor/help.promoData" />
///</summary>
[TlObject(0x8a4d87a)]
public sealed class TPromoData : IPromoData
{
    public uint ConstructorId => 0x8a4d87a;
    ///<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>
    /// MTProxy-related channel
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Proxy { get; set; }

    ///<summary>
    /// Expiry of PSA/MTProxy info
    ///</summary>
    public int Expires { get; set; }

    ///<summary>
    /// MTProxy/PSA peer
    /// See <a href="https://corefork.telegram.org/type/Peer" />
    ///</summary>
    public MyTelegram.Schema.IPeer? Peer { get; set; }

    ///<summary>
    /// PSA type
    ///</summary>
    public string? PsaType { get; set; }

    ///<summary>
    /// PSA message
    ///</summary>
    public string? PsaMessage { get; set; }
    public TVector<string> PendingSuggestions { get; set; }
    public TVector<string> DismissedSuggestions { get; set; }
    public MyTelegram.Schema.IPendingSuggestion? CustomPendingSuggestion { get; set; }

    ///<summary>
    /// Chat info
    ///</summary>
    public TVector<MyTelegram.Schema.IChat> Chats { get; set; }

    ///<summary>
    /// User info
    ///</summary>
    public TVector<MyTelegram.Schema.IUser> Users { get; set; }

    public void ComputeFlag()
    {
        if (Proxy) { Flags = Flags.SetBit(0); }
        if (Peer != null) { Flags = Flags.SetBit(3); }
        if (PsaType != null) { Flags = Flags.SetBit(1); }
        if (PsaMessage != null) { Flags = Flags.SetBit(2); }
        if (CustomPendingSuggestion != null) { Flags = Flags.SetBit(4); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Expires);
        if (Flags.IsBitSet(3)) { writer.Write(Peer); }
        if (Flags.IsBitSet(1)) { writer.Write(PsaType); }
        if (Flags.IsBitSet(2)) { writer.Write(PsaMessage); }
        writer.Write(PendingSuggestions);
        writer.Write(DismissedSuggestions);
        if (Flags.IsBitSet(4)) { writer.Write(CustomPendingSuggestion); }
        writer.Write(Chats);
        writer.Write(Users);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Proxy = true; }
        Expires = buffer.ReadInt32();
        if (Flags.IsBitSet(3)) { Peer = buffer.Read<MyTelegram.Schema.IPeer>(); }
        if (Flags.IsBitSet(1)) { PsaType = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { PsaMessage = buffer.ReadString(); }
        PendingSuggestions = buffer.Read<TVector<string>>();
        DismissedSuggestions = buffer.Read<TVector<string>>();
        if (Flags.IsBitSet(4)) { CustomPendingSuggestion = buffer.Read<MyTelegram.Schema.IPendingSuggestion>(); }
        Chats = buffer.Read<TVector<MyTelegram.Schema.IChat>>();
        Users = buffer.Read<TVector<MyTelegram.Schema.IUser>>();
    }
}