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

namespace MyTelegram.Schema.Account;

///<summary>
/// Upload theme
/// <para>Possible errors</para>
/// Code Type Description
/// 400 THEME_FILE_INVALID Invalid theme file provided.
/// 400 THEME_MIME_INVALID The theme's MIME type is invalid.
/// See <a href="https://corefork.telegram.org/method/account.uploadTheme" />
///</summary>
[TlObject(0x1c3db333)]
public sealed class RequestUploadTheme : IRequest<MyTelegram.Schema.IDocument>
{
    public uint ConstructorId => 0x1c3db333;
    ///<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>
    /// <a href="https://corefork.telegram.org/api/themes#uploading-theme-files">Previously uploaded</a> theme file with platform-specific colors for UI components, can be left unset when creating themes that only modify the wallpaper or accent colors.
    /// See <a href="https://corefork.telegram.org/type/InputFile" />
    ///</summary>
    public MyTelegram.Schema.IInputFile File { get; set; }

    ///<summary>
    /// Thumbnail
    /// See <a href="https://corefork.telegram.org/type/InputFile" />
    ///</summary>
    public MyTelegram.Schema.IInputFile? Thumb { get; set; }

    ///<summary>
    /// File name
    ///</summary>
    public string FileName { get; set; }

    ///<summary>
    /// MIME type, must be <code>application/x-tgtheme-{format}</code>, where <code>format</code> depends on the client
    ///</summary>
    public string MimeType { get; set; }

    public void ComputeFlag()
    {
        if (Thumb != null) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(File);
        if (Flags.IsBitSet(0)) { writer.Write(Thumb); }
        writer.Write(FileName);
        writer.Write(MimeType);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        File = buffer.Read<MyTelegram.Schema.IInputFile>();
        if (Flags.IsBitSet(0)) { Thumb = buffer.Read<MyTelegram.Schema.IInputFile>(); }
        FileName = buffer.ReadString();
        MimeType = buffer.ReadString();
    }
}
