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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Sends a message to a chat
/// <para>Possible errors</para>
/// Code Type Description
/// 400 ADMIN_RIGHTS_EMPTY The chatAdminRights constructor passed in keyboardButtonRequestPeer.peer_type.user_admin_rights has no rights set (i.e. flags is 0).
/// 400 BOT_DOMAIN_INVALID Bot domain invalid.
/// 400 BOT_INVALID This is not a valid bot.
/// 400 BUSINESS_PEER_INVALID Messages can't be set to the specified peer through the current <a href="https://corefork.telegram.org/api/business#connected-bots">business connection</a>.
/// 400 BUTTON_DATA_INVALID The data of one or more of the buttons you provided is invalid.
/// 400 BUTTON_TYPE_INVALID The type of one or more of the buttons you provided is invalid.
/// 400 BUTTON_URL_INVALID Button URL invalid.
/// 400 BUTTON_USER_INVALID The <code>user_id</code> passed to inputKeyboardButtonUserProfile is invalid!
/// 400 BUTTON_USER_PRIVACY_RESTRICTED The privacy setting of the user specified in a <a href="https://corefork.telegram.org/constructor/inputKeyboardButtonUserProfile">inputKeyboardButtonUserProfile</a> button do not allow creating such a button.
/// 400 CHANNEL_INVALID The provided channel is invalid.
/// 406 CHANNEL_PRIVATE You haven't joined this channel/supergroup.
/// 403 CHAT_ADMIN_REQUIRED You must be an admin in this chat to do this.
/// 403 CHAT_GUEST_SEND_FORBIDDEN You join the discussion group before commenting, see <a href="https://corefork.telegram.org/api/discussion#requiring-users-to-join-the-group">here&nbsp;»</a> for more info.
/// 400 CHAT_ID_INVALID The provided chat id is invalid.
/// 400 CHAT_RESTRICTED You can't send messages in this chat, you were restricted.
/// 403 CHAT_SEND_PLAIN_FORBIDDEN You can't send non-media (text) messages in this chat.
/// 403 CHAT_WRITE_FORBIDDEN You can't write in this chat.
/// 400 DOCUMENT_INVALID The specified document is invalid.
/// 400 ENCRYPTION_DECLINED The secret chat was declined.
/// 400 ENTITIES_TOO_LONG You provided too many styled message entities.
/// 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 ENTITY_MENTION_USER_INVALID You mentioned an invalid user.
/// 400 FROM_MESSAGE_BOT_DISABLED Bots can't use fromMessage min constructors.
/// 400 INPUT_USER_DEACTIVATED The specified user was deleted.
/// 400 MESSAGE_EMPTY The provided message is empty.
/// 400 MESSAGE_TOO_LONG The provided message is too long.
/// 400 MSG_ID_INVALID Invalid message ID provided.
/// 500 MSG_WAIT_FAILED A waiting call returned an error.
/// 406 PAYMENT_UNSUPPORTED A detailed description of the error will be received separately as described <a href="https://corefork.telegram.org/api/errors#406-not-acceptable">here&nbsp;»</a>.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 PINNED_DIALOGS_TOO_MUCH Too many pinned dialogs.
/// 400 POLL_OPTION_INVALID Invalid poll option provided.
/// 406 PRIVACY_PREMIUM_REQUIRED You need a <a href="https://corefork.telegram.org/api/premium">Telegram Premium subscription</a> to send a message to this user.
/// 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.
/// 400 QUOTE_TEXT_INVALID The specified <code>reply_to</code>.<code>quote_text</code> field is invalid.
/// 500 RANDOM_ID_DUPLICATE You provided a random ID that was already used.
/// 400 REPLY_MARKUP_INVALID The provided reply markup is invalid.
/// 400 REPLY_MARKUP_TOO_LONG The specified reply_markup is too long.
/// 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 REPLY_MESSAGE_ID_INVALID The specified reply-to message ID is invalid.
/// 400 REPLY_TO_INVALID The specified <code>reply_to</code> field is invalid.
/// 400 REPLY_TO_USER_INVALID The replied-to user is invalid.
/// 400 SCHEDULE_BOT_NOT_ALLOWED Bots cannot schedule messages.
/// 400 SCHEDULE_DATE_TOO_LATE You can't schedule a message this far in the future.
/// 400 SCHEDULE_STATUS_PRIVATE Can't schedule until user is online, if the user's last seen timestamp is hidden by their privacy settings.
/// 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 STORY_ID_INVALID The specified story ID is invalid.
/// 406 TOPIC_CLOSED This topic was closed, you can't send messages to it anymore.
/// 406 TOPIC_DELETED The specified topic was deleted.
/// 400 USER_BANNED_IN_CHANNEL You're banned from sending messages in supergroups/channels.
/// 403 USER_IS_BLOCKED You were blocked by this user.
/// 400 USER_IS_BOT Bots can't send messages to other bots.
/// 400 WC_CONVERT_URL_INVALID WC convert URL invalid.
/// 400 YOU_BLOCKED_USER You blocked this user.
/// See <a href="https://corefork.telegram.org/method/messages.sendMessage" />
///</summary>
[TlObject(0xfe05dc9a)]
public sealed class RequestSendMessage : IRequest<MyTelegram.Schema.IUpdates>
{
    public uint ConstructorId => 0xfe05dc9a;
    ///<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 to disable generation of the webpage preview
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool NoWebpage { get; set; }

    ///<summary>
    /// Send this message silently (no notifications for the receivers)
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Silent { get; set; }

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

    ///<summary>
    /// Clear the draft field
    /// 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 where the message will be sent
    /// 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. <br>Also used to quote other messages.
    /// See <a href="https://corefork.telegram.org/type/InputReplyTo" />
    ///</summary>
    public MyTelegram.Schema.IInputReplyTo? ReplyTo { get; set; }

    ///<summary>
    /// The message
    ///</summary>
    public string Message { get; set; }

    ///<summary>
    /// Unique client message ID required to prevent message resending
    ///</summary>
    public long RandomId { get; set; }

    ///<summary>
    /// Reply markup for sending bot buttons
    /// See <a href="https://corefork.telegram.org/type/ReplyMarkup" />
    ///</summary>
    public MyTelegram.Schema.IReplyMarkup? ReplyMarkup { get; set; }

    ///<summary>
    /// Message <a href="https://corefork.telegram.org/api/entities">entities</a> for sending styled text
    ///</summary>
    public TVector<MyTelegram.Schema.IMessageEntity>? Entities { get; set; }

    ///<summary>
    /// Scheduled message date for <a href="https://corefork.telegram.org/api/scheduled-messages">scheduled messages</a>
    ///</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 MyTelegram.Schema.ISuggestedPost? SuggestedPost { get; set; }

    public void ComputeFlag()
    {
        if (NoWebpage) { Flags = Flags.SetBit(1); }
        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 (ReplyMarkup != null) { Flags = Flags.SetBit(2); }
        if (Entities?.Count > 0) { Flags = Flags.SetBit(3); }
        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); }
        if (SuggestedPost != null) { Flags = Flags.SetBit(22); }
    }

    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(Message);
        writer.Write(RandomId);
        if (Flags.IsBitSet(2)) { writer.Write(ReplyMarkup); }
        if (Flags.IsBitSet(3)) { writer.Write(Entities); }
        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); }
        if (Flags.IsBitSet(22)) { writer.Write(SuggestedPost); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { NoWebpage = true; }
        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>(); }
        Message = buffer.ReadString();
        RandomId = buffer.ReadInt64();
        if (Flags.IsBitSet(2)) { ReplyMarkup = buffer.Read<MyTelegram.Schema.IReplyMarkup>(); }
        if (Flags.IsBitSet(3)) { Entities = buffer.Read<TVector<MyTelegram.Schema.IMessageEntity>>(); }
        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(); }
        if (Flags.IsBitSet(22)) { SuggestedPost = buffer.Read<MyTelegram.Schema.ISuggestedPost>(); }
    }
}
