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

namespace MyTelegram.Schema;

///<summary>
/// Used to buy a <a href="https://corefork.telegram.org/api/gifts">Telegram Star Gift, see here »</a> for more info.
/// See <a href="https://corefork.telegram.org/constructor/inputInvoiceStarGift" />
///</summary>
[TlObject(0xe8625e92)]
public sealed class TInputInvoiceStarGift : IInputInvoice
{
    public uint ConstructorId => 0xe8625e92;
    ///<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>
    /// If set, your name will be hidden if the destination user decides to display the gift on their profile (they will still see that you sent the gift)
    /// See <a href="https://corefork.telegram.org/type/true" />
    ///</summary>
    public bool HideName { get; set; }
    public bool IncludeUpgrade { get; set; }
    public MyTelegram.Schema.IInputPeer Peer { get; set; }

    ///<summary>
    /// Identifier of the gift, from <a href="https://corefork.telegram.org/constructor/starGift">starGift</a>.<code>id</code>
    ///</summary>
    public long GiftId { get; set; }

    ///<summary>
    /// Optional message, attached with the gift. <br>The maximum length for this field is specified in the <a href="https://corefork.telegram.org/api/config#stargifts-message-length-max">stargifts_message_length_max client configuration value »</a>.
    /// See <a href="https://corefork.telegram.org/type/TextWithEntities" />
    ///</summary>
    public MyTelegram.Schema.ITextWithEntities? Message { get; set; }

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

    public void Serialize(IBufferWriter<byte> writer)
    {
        ComputeFlag();
        writer.Write(ConstructorId);
        writer.Write(Flags);
        writer.Write(Peer);
        writer.Write(GiftId);
        if (Flags.IsBitSet(1)) { writer.Write(Message); }
    }

    public void Deserialize(ref ReadOnlyMemory<byte> buffer)
    {
        Flags = buffer.ReadInt32();
        if (Flags.IsBitSet(0)) { HideName = true; }
        if (Flags.IsBitSet(2)) { IncludeUpgrade = true; }
        Peer = buffer.Read<MyTelegram.Schema.IInputPeer>();
        GiftId = buffer.ReadInt64();
        if (Flags.IsBitSet(1)) { Message = buffer.Read<MyTelegram.Schema.ITextWithEntities>(); }
    }
}