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

namespace MyTelegram.Schema.Account;

///<summary>
/// Install a theme
/// See <a href="https://corefork.telegram.org/method/account.installTheme" />
///</summary>
[TlObject(0xc727bb3b)]
public sealed class RequestInstallTheme : IRequest<IBool>
{
    public uint ConstructorId => 0xc727bb3b;
    ///<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 to install the dark version
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Dark { get; set; }

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

    ///<summary>
    /// Theme format, a string that identifies the theming engines supported by the client
    ///</summary>
    public string? Format { get; set; }

    ///<summary>
    /// Indicates a basic theme provided by all clients
    /// See <a href="https://corefork.telegram.org/type/BaseTheme" />
    ///</summary>
    public MyTelegram.Schema.IBaseTheme? BaseTheme { get; set; }

    public void ComputeFlag()
    {
        if (Dark) { Flags = Flags.SetBit(0); }
        if (Theme != null) { Flags = Flags.SetBit(1); }
        if (Format != null) { Flags = Flags.SetBit(2); }
        if (BaseTheme != null) { Flags = Flags.SetBit(3); }
    }

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

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Dark = true; }
        if (Flags.IsBitSet(1)) { Theme = buffer.Read<MyTelegram.Schema.IInputTheme>(); }
        if (Flags.IsBitSet(2)) { Format = buffer.ReadString(); }
        if (Flags.IsBitSet(3)) { BaseTheme = buffer.Read<MyTelegram.Schema.IBaseTheme>(); }
    }
}
