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

namespace MyTelegram.Schema;

///<summary>
/// Page theme
/// See <a href="https://corefork.telegram.org/constructor/webPageAttributeTheme" />
///</summary>
[TlObject(0x54b56617)]
public sealed class TWebPageAttributeTheme : IWebPageAttribute
{
    public uint ConstructorId => 0x54b56617;
    ///<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>
    /// Theme files
    ///</summary>
    public TVector<MyTelegram.Schema.IDocument>? Documents { get; set; }

    ///<summary>
    /// Theme settings
    /// See <a href="https://corefork.telegram.org/type/ThemeSettings" />
    ///</summary>
    public MyTelegram.Schema.IThemeSettings? Settings { get; set; }

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

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Documents = buffer.Read<TVector<MyTelegram.Schema.IDocument>>(); }
        if (Flags.IsBitSet(1)) { Settings = buffer.Read<MyTelegram.Schema.IThemeSettings>(); }
    }
}