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

namespace MyTelegram.Schema.Channels;

///<summary>
/// Create a <a href="https://corefork.telegram.org/api/forum">forum topic</a>; requires <a href="https://corefork.telegram.org/api/rights"><code>manage_topics</code> rights</a>.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_FORUM_MISSING This supergroup is not a forum.
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 403 CHAT_WRITE_FORBIDDEN You can't write in this chat.
/// 403 PREMIUM_ACCOUNT_REQUIRED A premium account is required to execute this action.
/// 400 TOPIC_TITLE_EMPTY The specified topic title is empty.
/// See <a href="https://corefork.telegram.org/method/channels.createForumTopic" />
///</summary>
[TlObject(0xf40c0224)]
public sealed class RequestCreateForumTopic : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xf40c0224;
    ///<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/forum">The forum</a>
    /// See <a href="https://corefork.telegram.org/type/InputChannel" />
    ///</summary>
    public MyTelegram.Schema.IInputChannel Channel { get; set; }

    ///<summary>
    /// Topic title (maximum UTF-8 length: 128)
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// If no custom emoji icon is specified, specifies the color of the fallback topic icon (RGB), one of <code>0x6FB9F0</code>, <code>0xFFD67E</code>, <code>0xCB86DB</code>, <code>0x8EEE98</code>, <code>0xFF93B2</code>, or <code>0xFB6F5F</code>.
    ///</summary>
    public int? IconColor { get; set; }

    ///<summary>
    /// ID of the <a href="https://corefork.telegram.org/api/custom-emoji">custom emoji</a> used as topic icon. <a href="https://corefork.telegram.org/api/premium">Telegram Premium</a> users can use any custom emoji, other users can only use the custom emojis contained in the <a href="https://corefork.telegram.org/constructor/inputStickerSetEmojiDefaultTopicIcons">inputStickerSetEmojiDefaultTopicIcons</a> emoji pack.
    ///</summary>
    public long? IconEmojiId { get; set; }

    ///<summary>
    /// Unique client message ID to prevent duplicate sending of the same event
    ///</summary>
    public long RandomId { get; set; }

    ///<summary>
    /// Create the topic as the specified peer
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer? SendAs { get; set; }

    public void ComputeFlag()
    {
        if (/*IconColor != 0 && */IconColor.HasValue) { Flags = Flags.SetBit(0); }
        if (/*IconEmojiId != 0 &&*/ IconEmojiId.HasValue) { Flags = Flags.SetBit(3); }
        if (SendAs != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Channel);
        writer.Write(Title);
        if (Flags.IsBitSet(0)) { writer.Write(IconColor.Value); }
        if (Flags.IsBitSet(3)) { writer.Write(IconEmojiId.Value); }
        writer.Write(RandomId);
        if (Flags.IsBitSet(2)) { writer.Write(SendAs); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Channel = buffer.Read<MyTelegram.Schema.IInputChannel>();
        Title = buffer.ReadString();
        if (Flags.IsBitSet(0)) { IconColor = buffer.ReadInt32(); }
        if (Flags.IsBitSet(3)) { IconEmojiId = buffer.ReadInt64(); }
        RandomId = buffer.ReadInt64();
        if (Flags.IsBitSet(2)) { SendAs = buffer.Read<MyTelegram.Schema.IInputPeer>(); }
    }
}
