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

namespace MyTelegram.Schema;

///<summary>
/// Represents a <a href="https://corefork.telegram.org/api/wallpapers">wallpaper</a> only based on colors/gradients.
/// See <a href="https://corefork.telegram.org/constructor/wallPaperNoFile" />
///</summary>
[TlObject(0xe0804116)]
public sealed class TWallPaperNoFile : IWallPaper
{
    public uint ConstructorId => 0xe0804116;
    ///<summary>
    /// Wallpaper ID
    ///</summary>
    public long Id { get; set; }

    ///<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>
    /// Whether this is the default wallpaper
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Default { get; set; }

    ///<summary>
    /// Whether this wallpaper should be used in dark mode.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Dark { get; set; }

    ///<summary>
    /// Info on how to generate the wallpaper.
    /// See <a href="https://corefork.telegram.org/type/WallPaperSettings" />
    ///</summary>
    public MyTelegram.Schema.IWallPaperSettings? Settings { get; set; }

    public void ComputeFlag()
    {
        if (Default) { Flags = Flags.SetBit(1); }
        if (Dark) { Flags = Flags.SetBit(4); }
        if (Settings != null) { Flags = Flags.SetBit(2); }
    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Id = buffer.ReadInt64();
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { Default = true; }
        if (Flags.IsBitSet(4)) { Dark = true; }
        if (Flags.IsBitSet(2)) { Settings = buffer.Read<MyTelegram.Schema.IWallPaperSettings>(); }
    }
}