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

namespace MyTelegram.Schema.Account.LayerN;

///<summary>
/// Create a theme
/// <para>Possible errors</para>
/// Code Type Description
/// 400 THEME_MIME_INVALID The theme's MIME type is invalid.
/// 400 THEME_TITLE_INVALID The specified theme title is invalid.
/// See <a href="https://corefork.telegram.org/method/account.createTheme" />
///</summary>
[TlObject(0x8432c21f)]
public sealed class RequestCreateTheme : IRequest<MyTelegram.Schema.ITheme>
{
    public uint ConstructorId => 0x8432c21f;
    ///<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>
    /// Unique theme ID used to generate <a href="https://corefork.telegram.org/api/links#theme-links">theme deep links</a>, can be empty to autogenerate a random 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, multiple values can be provided for the different base themes (day/night mode, etc).
    /// See <a href="https://corefork.telegram.org/type/InputThemeSettings" />
    ///</summary>
    public MyTelegram.Schema.IInputThemeSettings? Settings { get; set; }

    public void ComputeFlag()
    {
        if (Document != null) { Flags = Flags.SetBit(2); }
        if (Settings != null) { Flags = Flags.SetBit(3); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Slug);
        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();
        Slug = buffer.ReadString();
        Title = buffer.ReadString();
        if (Flags.IsBitSet(2)) { Document = buffer.Read<MyTelegram.Schema.IInputDocument>(); }
        if (Flags.IsBitSet(3)) { Settings = buffer.Read<MyTelegram.Schema.IInputThemeSettings>(); }
    }
}
