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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Send an <a href="https://corefork.telegram.org/api/files#albums-grouped-media">album or grouped media</a>
/// <para>Possible errors</para>
/// Code Type Description
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 400 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 400 CHAT_ADMIN_REQUIRED You must be an admin in this chat to do this.
/// 400 CHAT_FORWARDS_RESTRICTED You can't forward messages from a protected chat.
/// 403 CHAT_SEND_MEDIA_FORBIDDEN You can't send media in this chat.
/// 403 CHAT_SEND_PHOTOS_FORBIDDEN You can't send photos in this chat.
/// 403 CHAT_SEND_VIDEOS_FORBIDDEN You can't send videos in this chat.
/// 403 CHAT_WRITE_FORBIDDEN You can't write in this chat.
/// 400 ENTITY_BOUNDS_INVALID A specified <a href="https://corefork.telegram.org/api/entities#entity-length">entity offset or length</a> is invalid, see <a href="https://corefork.telegram.org/api/entities#entity-length">here&nbsp;»</a> for info on how to properly compute the entity offset/length.
/// 400 FILE_REFERENCE_%d_EXPIRED The file reference of the media file at index %d in the passed media array expired, it <a href="https://corefork.telegram.org/api/file_reference">must be refreshed</a>.
/// 400 FILE_REFERENCE_%d_INVALID The file reference of the media file at index %d in the passed media array is invalid.
/// 400 MEDIA_CAPTION_TOO_LONG The caption is too long.
/// 400 MEDIA_EMPTY The provided media object is invalid.
/// 400 MEDIA_INVALID Media invalid.
/// 400 MULTI_MEDIA_TOO_LONG Too many media files for album.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 QUICK_REPLIES_TOO_MUCH A maximum of <a href="https://corefork.telegram.org/api/config#quick-replies-limit">appConfig.<code>quick_replies_limit</code></a> shortcuts may be created, the limit was reached.
/// 500 RANDOM_ID_DUPLICATE You provided a random ID that was already used.
/// 400 RANDOM_ID_EMPTY Random ID empty.
/// 400 REPLY_MESSAGES_TOO_MUCH Each shortcut can contain a maximum of <a href="https://corefork.telegram.org/api/config#quick-reply-messages-limit">appConfig.<code>quick_reply_messages_limit</code></a> messages, the limit was reached.
/// 400 SCHEDULE_DATE_TOO_LATE You can't schedule a message this far in the future.
/// 400 SCHEDULE_TOO_MUCH There are too many scheduled messages.
/// 400 SEND_AS_PEER_INVALID You can't send messages as the specified peer.
/// 420 SLOWMODE_WAIT_%d Slowmode is enabled in this chat: wait %d seconds before sending another message to this chat.
/// 400 TOPIC_CLOSED This topic was closed, you can't send messages to it anymore.
/// 400 TOPIC_DELETED The specified topic was deleted.
/// 400 USER_BANNED_IN_CHANNEL You're banned from sending messages in supergroups/channels.
/// See <a href="https://corefork.telegram.org/method/messages.sendMultiMedia" />
///</summary>
[TlObject(0x1bf89d74)]
public sealed class RequestSendMultiMedia : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0x1bf89d74;
    ///<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 to send the album silently (no notification triggered)
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Silent { get; set; }

    ///<summary>
    /// Send in background?
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Background { get; set; }

    ///<summary>
    /// Whether to clear <a href="https://corefork.telegram.org/api/drafts">drafts</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ClearDraft { get; set; }

    ///<summary>
    /// Only for bots, disallows forwarding and saving of the messages, even if the destination chat doesn't have <a href="https://telegram.org/blog/protected-content-delete-by-date-and-more">content protection</a> enabled
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Noforwards { get; set; }

    ///<summary>
    /// Whether to move used stickersets to top, <a href="https://corefork.telegram.org/api/stickers#recent-stickersets">see here for more info on this flag »</a>
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool UpdateStickersetsOrder { get; set; }

    ///<summary>
    /// If set, any eventual webpage preview will be shown on top of the message instead of at the bottom.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool InvertMedia { get; set; }

    ///<summary>
    /// Bots only: if set, allows sending up to 1000 messages per second, ignoring <a href="https://corefork.telegram.org/bots/faq#how-can-i-message-all-of-my-bot-39s-subscribers-at-once">broadcasting limits</a> for a fee of 0.1 Telegram Stars per message. The relevant Stars will be withdrawn from the bot's balance.
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool AllowPaidFloodskip { get; set; }

    ///<summary>
    /// The destination chat
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// If set, indicates that the message should be sent in reply to the specified message or story.
    /// See <a href="https://corefork.telegram.org/type/InputReplyTo" />
    ///</summary>
    public MyTelegram.Schema.IInputReplyTo? ReplyTo { get; set; }

    ///<summary>
    /// The medias to send: note that they must be separately uploaded using <a href="https://corefork.telegram.org/method/messages.uploadMedia">messages.uploadMedia</a> first, using raw <code>inputMediaUploaded*</code> constructors is not supported.
    ///</summary>
    public TVector<MyTelegram.Schema.IInputSingleMedia> MultiMedia { get; set; }

    ///<summary>
    /// Scheduled message date for scheduled messages
    ///</summary>
    public int? ScheduleDate { get; set; }

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

    ///<summary>
    /// Add the message to the specified <a href="https://corefork.telegram.org/api/business#quick-reply-shortcuts">quick reply shortcut »</a>, instead.
    /// See <a href="https://corefork.telegram.org/type/InputQuickReplyShortcut" />
    ///</summary>
    public MyTelegram.Schema.IInputQuickReplyShortcut? QuickReplyShortcut { get; set; }

    ///<summary>
    /// Specifies a <a href="https://corefork.telegram.org/api/effects">message effect »</a> to use for the message.
    ///</summary>
    public long? Effect { get; set; }
    public long? AllowPaidStars { get; set; }

    public void ComputeFlag()
    {
        if (Silent) { Flags = Flags.SetBit(5); }
        if (Background) { Flags = Flags.SetBit(6); }
        if (ClearDraft) { Flags = Flags.SetBit(7); }
        if (Noforwards) { Flags = Flags.SetBit(14); }
        if (UpdateStickersetsOrder) { Flags = Flags.SetBit(15); }
        if (InvertMedia) { Flags = Flags.SetBit(16); }
        if (AllowPaidFloodskip) { Flags = Flags.SetBit(19); }
        if (ReplyTo != null) { Flags = Flags.SetBit(0); }
        if (/*ScheduleDate != 0 && */ScheduleDate.HasValue) { Flags = Flags.SetBit(10); }
        if (SendAs != null) { Flags = Flags.SetBit(13); }
        if (QuickReplyShortcut != null) { Flags = Flags.SetBit(17); }
        if (/*Effect != 0 &&*/ Effect.HasValue) { Flags = Flags.SetBit(18); }
        if (/*AllowPaidStars != 0 &&*/ AllowPaidStars.HasValue) { Flags = Flags.SetBit(21); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        if (Flags.IsBitSet(0)) { writer.Write(ReplyTo); }
        writer.Write(MultiMedia);
        if (Flags.IsBitSet(10)) { writer.Write(ScheduleDate.Value); }
        if (Flags.IsBitSet(13)) { writer.Write(SendAs); }
        if (Flags.IsBitSet(17)) { writer.Write(QuickReplyShortcut); }
        if (Flags.IsBitSet(18)) { writer.Write(Effect.Value); }
        if (Flags.IsBitSet(21)) { writer.Write(AllowPaidStars.Value); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(5)) { Silent = true; }
        if (Flags.IsBitSet(6)) { Background = true; }
        if (Flags.IsBitSet(7)) { ClearDraft = true; }
        if (Flags.IsBitSet(14)) { Noforwards = true; }
        if (Flags.IsBitSet(15)) { UpdateStickersetsOrder = true; }
        if (Flags.IsBitSet(16)) { InvertMedia = true; }
        if (Flags.IsBitSet(19)) { AllowPaidFloodskip = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        if (Flags.IsBitSet(0)) { ReplyTo = buffer.Read<MyTelegram.Schema.IInputReplyTo>(); }
        MultiMedia = buffer.Read<TVector<MyTelegram.Schema.IInputSingleMedia>>();
        if (Flags.IsBitSet(10)) { ScheduleDate = buffer.ReadInt32(); }
        if (Flags.IsBitSet(13)) { SendAs = buffer.Read<MyTelegram.Schema.IInputPeer>(); }
        if (Flags.IsBitSet(17)) { QuickReplyShortcut = buffer.Read<MyTelegram.Schema.IInputQuickReplyShortcut>(); }
        if (Flags.IsBitSet(18)) { Effect = buffer.ReadInt64(); }
        if (Flags.IsBitSet(21)) { AllowPaidStars = buffer.ReadInt64(); }
    }
}
