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

namespace MyTelegram.Schema;

///<summary>
/// Send an invoice
/// See <a href="https://corefork.telegram.org/constructor/botInlineMessageMediaInvoice" />
///</summary>
[TlObject(0x354a9b09)]
public sealed class TBotInlineMessageMediaInvoice : IBotInlineMessage
{
    public uint ConstructorId => 0x354a9b09;
    ///<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 if you require the user's shipping address to complete the order
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool ShippingAddressRequested { get; set; }

    ///<summary>
    /// Test invoice
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool Test { get; set; }

    ///<summary>
    /// Product name, 1-32 characters
    ///</summary>
    public string Title { get; set; }

    ///<summary>
    /// Product description, 1-255 characters
    ///</summary>
    public string Description { get; set; }

    ///<summary>
    /// Product photo
    /// See <a href="https://corefork.telegram.org/type/WebDocument" />
    ///</summary>
    public MyTelegram.Schema.IWebDocument? Photo { 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 price 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; }

    ///<summary>
    /// Inline keyboard
    /// See <a href="https://corefork.telegram.org/type/ReplyMarkup" />
    ///</summary>
    public MyTelegram.Schema.IReplyMarkup? ReplyMarkup { get; set; }

    public void ComputeFlag()
    {
        if (ShippingAddressRequested) { Flags = Flags.SetBit(1); }
        if (Test) { Flags = Flags.SetBit(3); }
        if (Photo != null) { Flags = Flags.SetBit(0); }
        if (ReplyMarkup != null) { Flags = Flags.SetBit(2); }
    }

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Title);
        writer.Write(Description);
        if (Flags.IsBitSet(0)) { writer.Write(Photo); }
        writer.Write(Currency);
        writer.Write(TotalAmount);
        if (Flags.IsBitSet(2)) { writer.Write(ReplyMarkup); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(1)) { ShippingAddressRequested = true; }
        if (Flags.IsBitSet(3)) { Test = true; }
        Title = buffer.ReadString();
        Description = buffer.ReadString();
        if (Flags.IsBitSet(0)) { Photo = buffer.Read<MyTelegram.Schema.IWebDocument>(); }
        Currency = buffer.ReadString();
        TotalAmount = buffer.ReadInt64();
        if (Flags.IsBitSet(2)) { ReplyMarkup = buffer.Read<MyTelegram.Schema.IReplyMarkup>(); }
    }
}