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

namespace MyTelegram.Schema.Account;

///<summary>
/// Update theme
/// <para>Possible errors</para>
/// Code Type Description
/// 400 THEME_INVALID Invalid theme provided.
/// See <a href="https://corefork.telegram.org/method/account.updateTheme" />
///</summary>
[TlObject(0x2bf40ccc)]
public sealed class RequestUpdateTheme : IRequest<MyTelegram.Schema.ITheme>
{
    public uint ConstructorId => 0x2bf40ccc;
    ///<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 format, a string that identifies the theming engines supported by the client
    ///</summary>
    public string Format { get; set; }

    ///<summary>
    /// Theme to update
    /// See <a href="https://corefork.telegram.org/type/InputTheme" />
    ///</summary>
    public MyTelegram.Schema.IInputTheme Theme { get; set; }

    ///<summary>
    /// Unique theme ID
    ///</summary>
    public string? Slug { get; set; }

    ///<summary>
    /// Theme name
    ///</summary>
    public string? Title { get; set; }

    ///<summary>
    /// Theme file
    /// See <a href="https://corefork.telegram.org/type/InputDocument" />
    ///</summary>
    public MyTelegram.Schema.IInputDocument? Document { get; set; }

    ///<summary>
    /// Theme settings
    ///</summary>
    public TVector<MyTelegram.Schema.IInputThemeSettings>? Settings { get; set; }

    public void ComputeFlag()
    {
        if (Slug != null) { Flags = Flags.SetBit(0); }
        if (Title != null) { Flags = Flags.SetBit(1); }
        if (Document != null) { Flags = Flags.SetBit(2); }
        if (Settings?.Count > 0) { Flags = Flags.SetBit(3); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Format);
        writer.Write(Theme);
        if (Flags.IsBitSet(0)) { writer.Write(Slug); }
        if (Flags.IsBitSet(1)) { writer.Write(Title); }
        if (Flags.IsBitSet(2)) { writer.Write(Document); }
        if (Flags.IsBitSet(3)) { writer.Write(Settings); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Format = buffer.ReadString();
        Theme = buffer.Read<MyTelegram.Schema.IInputTheme>();
        if (Flags.IsBitSet(0)) { Slug = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { Title = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { Document = buffer.Read<MyTelegram.Schema.IInputDocument>(); }
        if (Flags.IsBitSet(3)) { Settings = buffer.Read<TVector<MyTelegram.Schema.IInputThemeSettings>>(); }
    }
}
