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

namespace MyTelegram.Schema.Messages;

///<summary>
/// Translate a given text.<a href="https://corefork.telegram.org/api/entities">Styled text entities</a> will only be preserved for <a href="https://corefork.telegram.org/api/premium">Telegram Premium</a> users.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 INPUT_TEXT_EMPTY The specified text is empty.
/// 400 INPUT_TEXT_TOO_LONG The specified text is too long.
/// 400 MSG_ID_INVALID Invalid message ID provided.
/// 400 PEER_ID_INVALID The provided peer id is invalid.
/// 400 TO_LANG_INVALID The specified destination language is invalid.
/// 400 TRANSLATE_REQ_QUOTA_EXCEEDED Translation is currently unavailable due to a temporary server-side lack of resources.
/// See <a href="https://corefork.telegram.org/method/messages.translateText" />
///</summary>
[TlObject(0x63183030)]
public sealed class RequestTranslateText : IRequest<MyTelegram.Schema.Messages.ITranslatedText>
{
    public uint ConstructorId => 0x63183030;
    ///<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>
    /// If the text is a chat message, the peer ID
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer? Peer { get; set; }

    ///<summary>
    /// A list of message IDs to translate
    ///</summary>
    public TVector<int>? Id { get; set; }

    ///<summary>
    /// A list of styled messages to translate
    ///</summary>
    public TVector<MyTelegram.Schema.ITextWithEntities>? Text { get; set; }

    ///<summary>
    /// Two-letter ISO 639-1 language code of the language to which the message is translated
    ///</summary>
    public string ToLang { get; set; }

    public void ComputeFlag()
    {
        if (Peer != null) { Flags = Flags.SetBit(0); }
        if (Id?.Count > 0) { Flags = Flags.SetBit(0); }
        if (Text?.Count > 0) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        if (Flags.IsBitSet(0)) { writer.Write(Peer); }
        if (Flags.IsBitSet(0)) { writer.Write(Id); }
        if (Flags.IsBitSet(1)) { writer.Write(Text); }
        writer.Write(ToLang);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { Peer = buffer.Read<MyTelegram.Schema.IInputPeer>(); }
        if (Flags.IsBitSet(0)) { Id = buffer.Read<TVector<int>>(); }
        if (Flags.IsBitSet(1)) { Text = buffer.Read<TVector<MyTelegram.Schema.ITextWithEntities>>(); }
        ToLang = buffer.ReadString();
    }
}
