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

namespace MyTelegram.Schema.Messages;

///<summary>
/// If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the bot will receive an <a href="https://corefork.telegram.org/constructor/updateBotShippingQuery">updateBotShippingQuery</a> update. Use this method to reply to shipping queries.
/// <para>Possible errors</para>
/// Code Type Description
/// 400 QUERY_ID_INVALID The query ID is invalid.
/// 400 USER_BOT_REQUIRED This method can only be called by a bot.
/// See <a href="https://corefork.telegram.org/method/messages.setBotShippingResults" />
///</summary>
[TlObject(0xe5f672fa)]
public sealed class RequestSetBotShippingResults : IRequest<IBool>
{
    public uint ConstructorId => 0xe5f672fa;
    ///<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>
    /// Unique identifier for the query to be answered
    ///</summary>
    public long QueryId { get; set; }

    ///<summary>
    /// Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable"). Telegram will display this message to the user.
    ///</summary>
    public string? Error { get; set; }

    ///<summary>
    /// A vector of available shipping options.
    ///</summary>
    public TVector<MyTelegram.Schema.IShippingOption>? ShippingOptions { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(QueryId);
        if (Flags.IsBitSet(0)) { writer.Write(Error); }
        if (Flags.IsBitSet(1)) { writer.Write(ShippingOptions); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        QueryId = buffer.ReadInt64();
        if (Flags.IsBitSet(0)) { Error = buffer.ReadString(); }
        if (Flags.IsBitSet(1)) { ShippingOptions = buffer.Read<TVector<MyTelegram.Schema.IShippingOption>>(); }
    }
}
