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

namespace MyTelegram.Schema;

///<summary>
/// Theme settings
/// See <a href="https://corefork.telegram.org/constructor/inputThemeSettings" />
///</summary>
[TlObject(0x8fde504f)]
public sealed class TInputThemeSettings : IInputThemeSettings
{
    public uint ConstructorId => 0x8fde504f;
    ///<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>
    /// If set, the freeform gradient fill needs to be animated on every sent message
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool MessageColorsAnimated { get; set; }

    ///<summary>
    /// Default theme on which this theme is based
    /// See <a href="https://corefork.telegram.org/type/BaseTheme" />
    ///</summary>
    public MyTelegram.Schema.IBaseTheme BaseTheme { get; set; }

    ///<summary>
    /// Accent color, ARGB format
    ///</summary>
    public int AccentColor { get; set; }

    ///<summary>
    /// Accent color of outgoing messages in ARGB format
    ///</summary>
    public int? OutboxAccentColor { get; set; }

    ///<summary>
    /// The fill to be used as a background for outgoing messages, in RGB24 format. <br>If just one or two equal colors are provided, describes a solid fill of a background. <br>If two different colors are provided, describes the top and bottom colors of a 0-degree gradient.<br>If three or four colors are provided, describes a freeform gradient fill of a background.
    ///</summary>
    public TVector<int>? MessageColors { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/constructor/inputWallPaper">inputWallPaper</a> or <a href="https://corefork.telegram.org/constructor/inputWallPaper">inputWallPaperSlug</a> when passing wallpaper files for <a href="https://corefork.telegram.org/api/wallpapers#image-wallpapers">image</a> or <a href="https://corefork.telegram.org/api/wallpapers#pattern-wallpapers">pattern</a> wallpapers, <a href="https://corefork.telegram.org/constructor/inputWallPaperNoFile">inputWallPaperNoFile</a> with <code>id=0</code> otherwise.
    /// See <a href="https://corefork.telegram.org/type/InputWallPaper" />
    ///</summary>
    public MyTelegram.Schema.IInputWallPaper? Wallpaper { get; set; }

    ///<summary>
    /// <a href="https://corefork.telegram.org/api/wallpapers">Wallpaper</a> settings.
    /// See <a href="https://corefork.telegram.org/type/WallPaperSettings" />
    ///</summary>
    public MyTelegram.Schema.IWallPaperSettings? WallpaperSettings { get; set; }

    public void ComputeFlag()
    {
        if (MessageColorsAnimated) { Flags = Flags.SetBit(2); }
        if (/*OutboxAccentColor != 0 && */OutboxAccentColor.HasValue) { Flags = Flags.SetBit(3); }
        if (MessageColors?.Count > 0) { Flags = Flags.SetBit(0); }
        if (Wallpaper != null) { Flags = Flags.SetBit(1); }
        if (WallpaperSettings != null) { Flags = Flags.SetBit(1); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(BaseTheme);
        writer.Write(AccentColor);
        if (Flags.IsBitSet(3)) { writer.Write(OutboxAccentColor.Value); }
        if (Flags.IsBitSet(0)) { writer.Write(MessageColors); }
        if (Flags.IsBitSet(1)) { writer.Write(Wallpaper); }
        if (Flags.IsBitSet(1)) { writer.Write(WallpaperSettings); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(2)) { MessageColorsAnimated = true; }
        BaseTheme = buffer.Read<MyTelegram.Schema.IBaseTheme>();
        AccentColor = buffer.ReadInt32();
        if (Flags.IsBitSet(3)) { OutboxAccentColor = buffer.ReadInt32(); }
        if (Flags.IsBitSet(0)) { MessageColors = buffer.Read<TVector<int>>(); }
        if (Flags.IsBitSet(1)) { Wallpaper = buffer.Read<MyTelegram.Schema.IInputWallPaper>(); }
        if (Flags.IsBitSet(1)) { WallpaperSettings = buffer.Read<MyTelegram.Schema.IWallPaperSettings>(); }
    }
}