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

namespace MyTelegram.Schema.Account;

///<summary>
/// Create and upload a new <a href="https://corefork.telegram.org/api/wallpapers">wallpaper</a>
/// <para>Possible errors</para>
/// Code Type Description
/// 400 WALLPAPER_FILE_INVALID The specified wallpaper file is invalid.
/// 400 WALLPAPER_MIME_INVALID The specified wallpaper MIME type is invalid.
/// See <a href="https://corefork.telegram.org/method/account.uploadWallPaper" />
///</summary>
[TlObject(0xe39a8f03)]
public sealed class RequestUploadWallPaper : IRequest<MyTelegram.Schema.IWallPaper>
{
    public uint ConstructorId => 0xe39a8f03;
    ///<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>
    /// Set this flag when uploading wallpapers to be passed to <a href="https://corefork.telegram.org/method/messages.setChatWallPaper">messages.setChatWallPaper</a>.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ForChat { get; set; }

    ///<summary>
    /// The JPG/PNG wallpaper
    /// See <a href="https://corefork.telegram.org/type/InputFile" />
    ///</summary>
    public MyTelegram.Schema.IInputFile File { get; set; }

    ///<summary>
    /// MIME type of uploaded wallpaper
    ///</summary>
    public string MimeType { get; set; }

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

    public void ComputeFlag()
    {
        if (ForChat) { Flags = Flags.SetBit(0); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(File);
        writer.Write(MimeType);
        writer.Write(Settings);
    }

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