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

namespace MyTelegram.Schema.Stickers;

///<summary>
/// Create a stickerset.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 PACK_SHORT_NAME_INVALID Short pack name invalid.
/// 400 PACK_SHORT_NAME_OCCUPIED A stickerpack with this name already exists.
/// 400 PACK_TITLE_INVALID The stickerpack title is invalid.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 STICKERS_EMPTY No sticker provided.
/// 400 STICKER_EMOJI_INVALID Sticker emoji invalid.
/// 400 STICKER_FILE_INVALID Sticker file invalid.
/// 400 STICKER_GIF_DIMENSIONS The specified video sticker has invalid dimensions.
/// 400 STICKER_PNG_DIMENSIONS Sticker png dimensions invalid.
/// 400 STICKER_PNG_NOPNG One of the specified stickers is not a valid PNG file.
/// 400 STICKER_TGS_NODOC You must send the animated sticker as a document.
/// 400 STICKER_TGS_NOTGS Invalid TGS sticker provided.
/// 400 STICKER_THUMB_PNG_NOPNG Incorrect stickerset thumb file provided, PNG / WEBP expected.
/// 400 STICKER_THUMB_TGS_NOTGS Incorrect stickerset TGS thumb file provided.
/// 400 STICKER_VIDEO_BIG The specified video sticker is too big.
/// 400 STICKER_VIDEO_NODOC You must send the video sticker as a document.
/// 400 STICKER_VIDEO_NOWEBM The specified video sticker is not in webm format.
/// 400 USER_ID_INVALID The provided user ID is invalid.
/// See <a href="https://corefork.telegram.org/method/stickers.createStickerSet" />
///</summary>
[TlObject(0x9021ab67)]
public sealed class RequestCreateStickerSet : IRequest<MyTelegram.Schema.Messages.IStickerSet>
{
    public uint ConstructorId => 0x9021ab67;
    ///<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 this is a mask stickerset
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Masks { get; set; }

    ///<summary>
    /// Whether this is a <a href="https://corefork.telegram.org/api/custom-emoji">custom emoji</a> stickerset.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Emojis { get; set; }

    ///<summary>
    /// Whether the color of TGS custom emojis contained in this set should be changed to the text color when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context. For custom emoji stickersets only.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool TextColor { get; set; }

    ///<summary>
    /// Stickerset owner
    /// See <a href="https://corefork.telegram.org/type/InputUser" />
    ///</summary>
    public MyTelegram.Schema.IInputUser UserId { get; set; }

    ///<summary>
    /// Stickerset name, <code>1-64</code> chars
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// Short name of sticker set, to be used in <a href="https://corefork.telegram.org/api/links#stickerset-links">sticker deep links »</a>. Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and, <strong>if called by a bot</strong>, must end in <code>"_by_&lt;bot_username&gt;"</code>. <code>&lt;bot_username&gt;</code> is case insensitive. 1-64 characters.
    ///</summary>
    public string ShortName { get; set; }

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

    ///<summary>
    /// Stickers
    ///</summary>
    public TVector<MyTelegram.Schema.IInputStickerSetItem> Stickers { get; set; }

    ///<summary>
    /// Used when <a href="https://corefork.telegram.org/import-stickers">importing stickers using the sticker import SDKs</a>, specifies the name of the software that created the stickers
    ///</summary>
    public string? Software { get; set; }

    public void ComputeFlag()
    {
        if (Masks) { Flags = Flags.SetBit(0); }
        if (Emojis) { Flags = Flags.SetBit(5); }
        if (TextColor) { Flags = Flags.SetBit(6); }
        if (Thumb != null) { Flags = Flags.SetBit(2); }
        if (Software != null) { Flags = Flags.SetBit(3); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(UserId);
        writer.Write(Title);
        writer.Write(ShortName);
        if (Flags.IsBitSet(2)) { writer.Write(Thumb); }
        writer.Write(Stickers);
        if (Flags.IsBitSet(3)) { writer.Write(Software); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Masks = true; }
        if (Flags.IsBitSet(5)) { Emojis = true; }
        if (Flags.IsBitSet(6)) { TextColor = true; }
        UserId = buffer.Read<MyTelegram.Schema.IInputUser>();
        Title = buffer.ReadString();
        ShortName = buffer.ReadString();
        if (Flags.IsBitSet(2)) { Thumb = buffer.Read<MyTelegram.Schema.IInputDocument>(); }
        Stickers = buffer.Read<TVector<MyTelegram.Schema.IInputStickerSetItem>>();
        if (Flags.IsBitSet(3)) { Software = buffer.ReadString(); }
    }
}
