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

namespace MyTelegram.Schema;

///<summary>
/// Generated invoice of a <a href="https://corefork.telegram.org/bots/payments">bot payment</a>
/// See <a href="https://corefork.telegram.org/constructor/inputMediaInvoice" />
///</summary>
[TlObject(0x405fef0d)]
public sealed class TInputMediaInvoice : IInputMedia
{
    public uint ConstructorId => 0x405fef0d;
    ///<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>
    /// Product name, 1-32 characters
    ///</summary>
    public string Title { get; set; }

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

    ///<summary>
    /// URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
    /// See <a href="https://corefork.telegram.org/type/InputWebDocument" />
    ///</summary>
    public MyTelegram.Schema.IInputWebDocument? Photo { get; set; }

    ///<summary>
    /// The actual invoice
    /// See <a href="https://corefork.telegram.org/type/Invoice" />
    ///</summary>
    public MyTelegram.Schema.IInvoice Invoice { get; set; }

    ///<summary>
    /// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
    ///</summary>
    public ReadOnlyMemory<byte> Payload { get; set; }

    ///<summary>
    /// Payments provider token, obtained via <a href="https://t.me/botfather">Botfather</a>
    ///</summary>
    public string? Provider { get; set; }

    ///<summary>
    /// JSON-encoded data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
    /// See <a href="https://corefork.telegram.org/type/DataJSON" />
    ///</summary>
    public MyTelegram.Schema.IDataJSON ProviderData { get; set; }

    ///<summary>
    /// Unique <a href="https://corefork.telegram.org/api/links#bot-links">bot deep links start parameter</a>. If present, forwarded copies of the sent message will have a URL button with a <a href="https://corefork.telegram.org/api/links#bot-links">deep link</a> to the bot (instead of a Pay button), with the value used as the start parameter. If absent, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice.
    ///</summary>
    public string? StartParam { get; set; }

    ///<summary>
    /// Deprecated
    /// See <a href="https://corefork.telegram.org/type/InputMedia" />
    ///</summary>
    public MyTelegram.Schema.IInputMedia? ExtendedMedia { get; set; }

    public void ComputeFlag()
    {
        if (Photo != null) { Flags = Flags.SetBit(0); }
        if (Provider != null) { Flags = Flags.SetBit(3); }
        if (StartParam != null) { Flags = Flags.SetBit(1); }
        if (ExtendedMedia != 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(Invoice);
        writer.Write(Payload);
        if (Flags.IsBitSet(3)) { writer.Write(Provider); }
        writer.Write(ProviderData);
        if (Flags.IsBitSet(1)) { writer.Write(StartParam); }
        if (Flags.IsBitSet(2)) { writer.Write(ExtendedMedia); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Title = buffer.ReadString();
        Description = buffer.ReadString();
        if (Flags.IsBitSet(0)) { Photo = buffer.Read<MyTelegram.Schema.IInputWebDocument>(); }
        Invoice = buffer.Read<MyTelegram.Schema.IInvoice>();
        Payload = buffer.ReadBytes();
        if (Flags.IsBitSet(3)) { Provider = buffer.ReadString(); }
        ProviderData = buffer.Read<MyTelegram.Schema.IDataJSON>();
        if (Flags.IsBitSet(1)) { StartParam = buffer.ReadString(); }
        if (Flags.IsBitSet(2)) { ExtendedMedia = buffer.Read<MyTelegram.Schema.IInputMedia>(); }
    }
}