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

namespace MyTelegram.Schema;

///<summary>
/// Used to gift <a href="https://corefork.telegram.org/api/premium">Telegram Premium</a> subscriptions only to some specific subscribers of a channel/supergroup or to some of our contacts, see <a href="https://corefork.telegram.org/api/giveaways">here »</a> for more info on giveaways and gifts.
/// See <a href="https://corefork.telegram.org/constructor/inputStorePaymentPremiumGiftCode" />
///</summary>
[TlObject(0xfb790393)]
public sealed class TInputStorePaymentPremiumGiftCode : IInputStorePaymentPurpose
{
    public uint ConstructorId => 0xfb790393;
    ///<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 users that will receive the <a href="https://corefork.telegram.org/api/premium">Telegram Premium</a> subscriptions.
    ///</summary>
    public TVector<MyTelegram.Schema.IInputUser> Users { get; set; }

    ///<summary>
    /// If set, the gifts will be sent on behalf of a channel/supergroup we are an admin of, which will also assign some <a href="https://corefork.telegram.org/api/boost">boosts</a> to it. Otherwise, the gift will be sent directly from the currently logged in user, and we will gain some extra <a href="https://corefork.telegram.org/api/boost">boost slots</a>. See <a href="https://corefork.telegram.org/api/giveaways">here »</a> for more info on giveaways and gifts.
    /// See <a href="https://corefork.telegram.org/type/InputPeer" />
    ///</summary>
    public MyTelegram.Schema.IInputPeer? BoostPeer { get; set; }

    ///<summary>
    /// Three-letter ISO 4217 <a href="https://corefork.telegram.org/bots/payments#supported-currencies">currency</a> code
    ///</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 Amount { get; set; }

    ///<summary>
    /// Message attached with the gift
    /// See <a href="https://corefork.telegram.org/type/TextWithEntities" />
    ///</summary>
    public MyTelegram.Schema.ITextWithEntities? Message { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Users);
        if (Flags.IsBitSet(0)) { writer.Write(BoostPeer); }
        writer.Write(Currency);
        writer.Write(Amount);
        if (Flags.IsBitSet(1)) { writer.Write(Message); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        Users = buffer.Read<TVector<MyTelegram.Schema.IInputUser>>();
        if (Flags.IsBitSet(0)) { BoostPeer = buffer.Read<MyTelegram.Schema.IInputPeer>(); }
        Currency = buffer.ReadString();
        Amount = buffer.ReadInt64();
        if (Flags.IsBitSet(1)) { Message = buffer.Read<MyTelegram.Schema.ITextWithEntities>(); }
    }
}