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

namespace MyTelegram.Schema;

///<summary>
/// <a href="https://corefork.telegram.org/api/paid-media">Paid media, see here »</a> for more info.
/// See <a href="https://corefork.telegram.org/constructor/inputMediaPaidMedia" />
///</summary>
[TlObject(0xc4103386)]
public sealed class TInputMediaPaidMedia : IInputMedia
{
    public uint ConstructorId => 0xc4103386;
    ///<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>
    /// The price of the media in <a href="https://corefork.telegram.org/api/stars">Telegram Stars</a>.
    ///</summary>
    public long StarsAmount { get; set; }

    ///<summary>
    /// Photos or videos.
    ///</summary>
    public TVector<MyTelegram.Schema.IInputMedia> ExtendedMedia { get; set; }

    ///<summary>
    /// Bots only, specifies a custom payload that will then be passed in <a href="https://corefork.telegram.org/constructor/updateBotPurchasedPaidMedia">updateBotPurchasedPaidMedia</a> when a payment is made (this field will not be visible to the user)
    ///</summary>
    public string? Payload { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(StarsAmount);
        writer.Write(ExtendedMedia);
        if (Flags.IsBitSet(0)) { writer.Write(Payload); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        StarsAmount = buffer.ReadInt64();
        ExtendedMedia = buffer.Read<TVector<MyTelegram.Schema.IInputMedia>>();
        if (Flags.IsBitSet(0)) { Payload = buffer.ReadString(); }
    }
}