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

namespace MyTelegram.Schema;

///<summary>
/// This object contains information about an incoming pre-checkout query.
/// See <a href="https://corefork.telegram.org/constructor/updateBotPrecheckoutQuery" />
///</summary>
[TlObject(0x8caa9a96)]
public sealed class TUpdateBotPrecheckoutQuery : IUpdate
{
    public uint ConstructorId => 0x8caa9a96;
    ///<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 query identifier
    ///</summary>
    public long QueryId { get; set; }

    ///<summary>
    /// User who sent the query
    ///</summary>
    public long UserId { get; set; }

    ///<summary>
    /// Bot specified invoice payload
    ///</summary>
    public ReadOnlyMemory<byte> Payload { get; set; }

    ///<summary>
    /// Order info provided by the user
    /// See <a href="https://corefork.telegram.org/type/PaymentRequestedInfo" />
    ///</summary>
    public MyTelegram.Schema.IPaymentRequestedInfo? Info { get; set; }

    ///<summary>
    /// Identifier of the shipping option chosen by the user
    ///</summary>
    public string? ShippingOptionId { get; set; }

    ///<summary>
    /// Three-letter ISO 4217 <a href="https://corefork.telegram.org/bots/payments#supported-currencies">currency</a> code, or <code>XTR</code> for <a href="https://corefork.telegram.org/api/stars">Telegram Stars</a>.
    ///</summary>
    public string Currency { get; set; }

    ///<summary>
    /// Total amount in the smallest units of the currency (integer, not float/double). For example, for a price of <code>US$ 1.45</code> pass <code>amount = 145</code>. See the exp parameter in <a href="https://corefork.telegram.org/bots/payments/currencies.json">currencies.json</a>, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
    ///</summary>
    public long TotalAmount { get; set; }

    public void ComputeFlag()
    {
        if (Info != null) { Flags = Flags.SetBit(0); }
        if (ShippingOptionId != null) { Flags = Flags.SetBit(1); }

    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(QueryId);
        writer.Write(UserId);
        writer.Write(Payload);
        if (Flags.IsBitSet(0)) { writer.Write(Info); }
        if (Flags.IsBitSet(1)) { writer.Write(ShippingOptionId); }
        writer.Write(Currency);
        writer.Write(TotalAmount);
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        QueryId = buffer.ReadInt64();
        UserId = buffer.ReadInt64();
        Payload = buffer.ReadBytes();
        if (Flags.IsBitSet(0)) { Info = buffer.Read<MyTelegram.Schema.IPaymentRequestedInfo>(); }
        if (Flags.IsBitSet(1)) { ShippingOptionId = buffer.ReadString(); }
        Currency = buffer.ReadString();
        TotalAmount = buffer.ReadInt64();
    }
}