// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	"context"
	"errors"
	"fmt"
	"sort"
	"strings"

	"go.uber.org/multierr"

	"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
	"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
)

// No-op definition for keeping imports.
var (
	_ = bin.Buffer{}
	_ = context.Background()
	_ = fmt.Stringer(nil)
	_ = strings.Builder{}
	_ = errors.Is
	_ = multierr.AppendInto
	_ = sort.Ints
	_ = tdp.Format
	_ = tgerr.Error{}
	_ = tdjson.Encoder{}
)

// SavedStarGift represents TL type `savedStarGift#8983a452`.
// Represents a gift¹ owned by a peer.
//
// Links:
//  1. https://core.telegram.org/api/gifts
//
// See https://core.telegram.org/constructor/savedStarGift for reference.
type SavedStarGift struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the gift sender in from_id and the message are set only for the receiver of
	// the gift.
	NameHidden bool
	// If set, the gift is not pinned on the user's profile.
	Unsaved bool
	// This gift was upgraded to a collectible gift »¹ and then re-downgraded to a regular
	// gift because a request to refund the payment related to the upgrade was made, and the
	// money was returned.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#collectible-gifts
	Refunded bool
	// Only set for non-collectible gifts, if they can be upgraded to a collectible gift »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#collectible-gifts
	CanUpgrade bool
	// Whether this gift is pinned on top of the user's profile page.
	PinnedToTop bool
	// If set, someone already separately pre-paid¹ for the upgrade of this gift.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#prepaying-for-someone-elses-upgrade
	UpgradeSeparate bool
	// Sender of the gift (unset for anonymous gifts).
	//
	// Use SetFromID and GetFromID helpers.
	FromID PeerClass
	// Reception date of the gift.
	Date int
	// The collectible gift.
	Gift StarGiftClass
	// Message attached to the gift.
	//
	// Use SetMessage and GetMessage helpers.
	Message TextWithEntities
	// For gifts received by users, ID to use in inputSavedStarGiftUser¹ constructors.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/inputSavedStarGiftUser
	//
	// Use SetMsgID and GetMsgID helpers.
	MsgID int
	// For gifts received by channels, ID to use in inputSavedStarGiftChat¹ constructors.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/inputSavedStarGiftChat
	//
	// Use SetSavedID and GetSavedID helpers.
	SavedID int64
	// For non-collectible gifts, the receiver of this gift may convert it to this many
	// Telegram Stars, instead of displaying it on their profile page.
	//
	// Use SetConvertStars and GetConvertStars helpers.
	ConvertStars int64
	// Only for pre-paid non-collectible gifts, the number of Telegram Stars the sender has
	// already paid to convert the gift into a collectible gift »¹ (this is different from
	// the meaning of the flag in messageActionStarGift², where it signals the upgrade price
	// for not yet upgraded gifts).
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#collectible-gifts
	//  2) https://core.telegram.org/constructor/messageActionStarGift
	//
	// Use SetUpgradeStars and GetUpgradeStars helpers.
	UpgradeStars int64
	// If set, indicates that the current gift can't be exported to the TON blockchain »¹
	// yet: the owner will be able to export it at the specified unixtime.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#withdraw-a-collectible-gift-to-the-ton-blockchain
	//
	// Use SetCanExportAt and GetCanExportAt helpers.
	CanExportAt int
	// If set, indicates that the gift can be transferred »¹ to another user by paying the
	// specified amount of stars.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#transferring-collectible-gifts
	//
	// Use SetTransferStars and GetTransferStars helpers.
	TransferStars int64
	// If set, indicates that the current gift can't be transferred »¹ yet: the owner will
	// be able to transfer it at the specified unixtime.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#transferring-collectible-gifts
	//
	// Use SetCanTransferAt and GetCanTransferAt helpers.
	CanTransferAt int
	// If set, indicates that the current gift can't be resold »¹ yet: the owner will be
	// able to put it up for sale at the specified unixtime.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#reselling-collectible-gifts
	//
	// Use SetCanResellAt and GetCanResellAt helpers.
	CanResellAt int
	// IDs of the collections »¹ that this gift is a part of.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#gift-collections
	//
	// Use SetCollectionID and GetCollectionID helpers.
	CollectionID []int
	// Hash to prepay for a gift upgrade separately »¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/gifts#prepaying-for-someone-elses-upgrade
	//
	// Use SetPrepaidUpgradeHash and GetPrepaidUpgradeHash helpers.
	PrepaidUpgradeHash string
	// DropOriginalDetailsStars field of SavedStarGift.
	//
	// Use SetDropOriginalDetailsStars and GetDropOriginalDetailsStars helpers.
	DropOriginalDetailsStars int64
}

// SavedStarGiftTypeID is TL type id of SavedStarGift.
const SavedStarGiftTypeID = 0x8983a452

// Ensuring interfaces in compile-time for SavedStarGift.
var (
	_ bin.Encoder     = &SavedStarGift{}
	_ bin.Decoder     = &SavedStarGift{}
	_ bin.BareEncoder = &SavedStarGift{}
	_ bin.BareDecoder = &SavedStarGift{}
)

func (s *SavedStarGift) Zero() bool {
	if s == nil {
		return true
	}
	if !(s.Flags.Zero()) {
		return false
	}
	if !(s.NameHidden == false) {
		return false
	}
	if !(s.Unsaved == false) {
		return false
	}
	if !(s.Refunded == false) {
		return false
	}
	if !(s.CanUpgrade == false) {
		return false
	}
	if !(s.PinnedToTop == false) {
		return false
	}
	if !(s.UpgradeSeparate == false) {
		return false
	}
	if !(s.FromID == nil) {
		return false
	}
	if !(s.Date == 0) {
		return false
	}
	if !(s.Gift == nil) {
		return false
	}
	if !(s.Message.Zero()) {
		return false
	}
	if !(s.MsgID == 0) {
		return false
	}
	if !(s.SavedID == 0) {
		return false
	}
	if !(s.ConvertStars == 0) {
		return false
	}
	if !(s.UpgradeStars == 0) {
		return false
	}
	if !(s.CanExportAt == 0) {
		return false
	}
	if !(s.TransferStars == 0) {
		return false
	}
	if !(s.CanTransferAt == 0) {
		return false
	}
	if !(s.CanResellAt == 0) {
		return false
	}
	if !(s.CollectionID == nil) {
		return false
	}
	if !(s.PrepaidUpgradeHash == "") {
		return false
	}
	if !(s.DropOriginalDetailsStars == 0) {
		return false
	}

	return true
}

// String implements fmt.Stringer.
func (s *SavedStarGift) String() string {
	if s == nil {
		return "SavedStarGift(nil)"
	}
	type Alias SavedStarGift
	return fmt.Sprintf("SavedStarGift%+v", Alias(*s))
}

// FillFrom fills SavedStarGift from given interface.
func (s *SavedStarGift) FillFrom(from interface {
	GetNameHidden() (value bool)
	GetUnsaved() (value bool)
	GetRefunded() (value bool)
	GetCanUpgrade() (value bool)
	GetPinnedToTop() (value bool)
	GetUpgradeSeparate() (value bool)
	GetFromID() (value PeerClass, ok bool)
	GetDate() (value int)
	GetGift() (value StarGiftClass)
	GetMessage() (value TextWithEntities, ok bool)
	GetMsgID() (value int, ok bool)
	GetSavedID() (value int64, ok bool)
	GetConvertStars() (value int64, ok bool)
	GetUpgradeStars() (value int64, ok bool)
	GetCanExportAt() (value int, ok bool)
	GetTransferStars() (value int64, ok bool)
	GetCanTransferAt() (value int, ok bool)
	GetCanResellAt() (value int, ok bool)
	GetCollectionID() (value []int, ok bool)
	GetPrepaidUpgradeHash() (value string, ok bool)
	GetDropOriginalDetailsStars() (value int64, ok bool)
}) {
	s.NameHidden = from.GetNameHidden()
	s.Unsaved = from.GetUnsaved()
	s.Refunded = from.GetRefunded()
	s.CanUpgrade = from.GetCanUpgrade()
	s.PinnedToTop = from.GetPinnedToTop()
	s.UpgradeSeparate = from.GetUpgradeSeparate()
	if val, ok := from.GetFromID(); ok {
		s.FromID = val
	}

	s.Date = from.GetDate()
	s.Gift = from.GetGift()
	if val, ok := from.GetMessage(); ok {
		s.Message = val
	}

	if val, ok := from.GetMsgID(); ok {
		s.MsgID = val
	}

	if val, ok := from.GetSavedID(); ok {
		s.SavedID = val
	}

	if val, ok := from.GetConvertStars(); ok {
		s.ConvertStars = val
	}

	if val, ok := from.GetUpgradeStars(); ok {
		s.UpgradeStars = val
	}

	if val, ok := from.GetCanExportAt(); ok {
		s.CanExportAt = val
	}

	if val, ok := from.GetTransferStars(); ok {
		s.TransferStars = val
	}

	if val, ok := from.GetCanTransferAt(); ok {
		s.CanTransferAt = val
	}

	if val, ok := from.GetCanResellAt(); ok {
		s.CanResellAt = val
	}

	if val, ok := from.GetCollectionID(); ok {
		s.CollectionID = val
	}

	if val, ok := from.GetPrepaidUpgradeHash(); ok {
		s.PrepaidUpgradeHash = val
	}

	if val, ok := from.GetDropOriginalDetailsStars(); ok {
		s.DropOriginalDetailsStars = val
	}

}

// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*SavedStarGift) TypeID() uint32 {
	return SavedStarGiftTypeID
}

// TypeName returns name of type in TL schema.
func (*SavedStarGift) TypeName() string {
	return "savedStarGift"
}

// TypeInfo returns info about TL type.
func (s *SavedStarGift) TypeInfo() tdp.Type {
	typ := tdp.Type{
		Name: "savedStarGift",
		ID:   SavedStarGiftTypeID,
	}
	if s == nil {
		typ.Null = true
		return typ
	}
	typ.Fields = []tdp.Field{
		{
			Name:       "NameHidden",
			SchemaName: "name_hidden",
			Null:       !s.Flags.Has(0),
		},
		{
			Name:       "Unsaved",
			SchemaName: "unsaved",
			Null:       !s.Flags.Has(5),
		},
		{
			Name:       "Refunded",
			SchemaName: "refunded",
			Null:       !s.Flags.Has(9),
		},
		{
			Name:       "CanUpgrade",
			SchemaName: "can_upgrade",
			Null:       !s.Flags.Has(10),
		},
		{
			Name:       "PinnedToTop",
			SchemaName: "pinned_to_top",
			Null:       !s.Flags.Has(12),
		},
		{
			Name:       "UpgradeSeparate",
			SchemaName: "upgrade_separate",
			Null:       !s.Flags.Has(17),
		},
		{
			Name:       "FromID",
			SchemaName: "from_id",
			Null:       !s.Flags.Has(1),
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "Gift",
			SchemaName: "gift",
		},
		{
			Name:       "Message",
			SchemaName: "message",
			Null:       !s.Flags.Has(2),
		},
		{
			Name:       "MsgID",
			SchemaName: "msg_id",
			Null:       !s.Flags.Has(3),
		},
		{
			Name:       "SavedID",
			SchemaName: "saved_id",
			Null:       !s.Flags.Has(11),
		},
		{
			Name:       "ConvertStars",
			SchemaName: "convert_stars",
			Null:       !s.Flags.Has(4),
		},
		{
			Name:       "UpgradeStars",
			SchemaName: "upgrade_stars",
			Null:       !s.Flags.Has(6),
		},
		{
			Name:       "CanExportAt",
			SchemaName: "can_export_at",
			Null:       !s.Flags.Has(7),
		},
		{
			Name:       "TransferStars",
			SchemaName: "transfer_stars",
			Null:       !s.Flags.Has(8),
		},
		{
			Name:       "CanTransferAt",
			SchemaName: "can_transfer_at",
			Null:       !s.Flags.Has(13),
		},
		{
			Name:       "CanResellAt",
			SchemaName: "can_resell_at",
			Null:       !s.Flags.Has(14),
		},
		{
			Name:       "CollectionID",
			SchemaName: "collection_id",
			Null:       !s.Flags.Has(15),
		},
		{
			Name:       "PrepaidUpgradeHash",
			SchemaName: "prepaid_upgrade_hash",
			Null:       !s.Flags.Has(16),
		},
		{
			Name:       "DropOriginalDetailsStars",
			SchemaName: "drop_original_details_stars",
			Null:       !s.Flags.Has(18),
		},
	}
	return typ
}

// SetFlags sets flags for non-zero fields.
func (s *SavedStarGift) SetFlags() {
	if !(s.NameHidden == false) {
		s.Flags.Set(0)
	}
	if !(s.Unsaved == false) {
		s.Flags.Set(5)
	}
	if !(s.Refunded == false) {
		s.Flags.Set(9)
	}
	if !(s.CanUpgrade == false) {
		s.Flags.Set(10)
	}
	if !(s.PinnedToTop == false) {
		s.Flags.Set(12)
	}
	if !(s.UpgradeSeparate == false) {
		s.Flags.Set(17)
	}
	if !(s.FromID == nil) {
		s.Flags.Set(1)
	}
	if !(s.Message.Zero()) {
		s.Flags.Set(2)
	}
	if !(s.MsgID == 0) {
		s.Flags.Set(3)
	}
	if !(s.SavedID == 0) {
		s.Flags.Set(11)
	}
	if !(s.ConvertStars == 0) {
		s.Flags.Set(4)
	}
	if !(s.UpgradeStars == 0) {
		s.Flags.Set(6)
	}
	if !(s.CanExportAt == 0) {
		s.Flags.Set(7)
	}
	if !(s.TransferStars == 0) {
		s.Flags.Set(8)
	}
	if !(s.CanTransferAt == 0) {
		s.Flags.Set(13)
	}
	if !(s.CanResellAt == 0) {
		s.Flags.Set(14)
	}
	if !(s.CollectionID == nil) {
		s.Flags.Set(15)
	}
	if !(s.PrepaidUpgradeHash == "") {
		s.Flags.Set(16)
	}
	if !(s.DropOriginalDetailsStars == 0) {
		s.Flags.Set(18)
	}
}

// Encode implements bin.Encoder.
func (s *SavedStarGift) Encode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedStarGift#8983a452 as nil")
	}
	b.PutID(SavedStarGiftTypeID)
	return s.EncodeBare(b)
}

// EncodeBare implements bin.BareEncoder.
func (s *SavedStarGift) EncodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't encode savedStarGift#8983a452 as nil")
	}
	s.SetFlags()
	if err := s.Flags.Encode(b); err != nil {
		return fmt.Errorf("unable to encode savedStarGift#8983a452: field flags: %w", err)
	}
	if s.Flags.Has(1) {
		if s.FromID == nil {
			return fmt.Errorf("unable to encode savedStarGift#8983a452: field from_id is nil")
		}
		if err := s.FromID.Encode(b); err != nil {
			return fmt.Errorf("unable to encode savedStarGift#8983a452: field from_id: %w", err)
		}
	}
	b.PutInt(s.Date)
	if s.Gift == nil {
		return fmt.Errorf("unable to encode savedStarGift#8983a452: field gift is nil")
	}
	if err := s.Gift.Encode(b); err != nil {
		return fmt.Errorf("unable to encode savedStarGift#8983a452: field gift: %w", err)
	}
	if s.Flags.Has(2) {
		if err := s.Message.Encode(b); err != nil {
			return fmt.Errorf("unable to encode savedStarGift#8983a452: field message: %w", err)
		}
	}
	if s.Flags.Has(3) {
		b.PutInt(s.MsgID)
	}
	if s.Flags.Has(11) {
		b.PutLong(s.SavedID)
	}
	if s.Flags.Has(4) {
		b.PutLong(s.ConvertStars)
	}
	if s.Flags.Has(6) {
		b.PutLong(s.UpgradeStars)
	}
	if s.Flags.Has(7) {
		b.PutInt(s.CanExportAt)
	}
	if s.Flags.Has(8) {
		b.PutLong(s.TransferStars)
	}
	if s.Flags.Has(13) {
		b.PutInt(s.CanTransferAt)
	}
	if s.Flags.Has(14) {
		b.PutInt(s.CanResellAt)
	}
	if s.Flags.Has(15) {
		b.PutVectorHeader(len(s.CollectionID))
		for _, v := range s.CollectionID {
			b.PutInt(v)
		}
	}
	if s.Flags.Has(16) {
		b.PutString(s.PrepaidUpgradeHash)
	}
	if s.Flags.Has(18) {
		b.PutLong(s.DropOriginalDetailsStars)
	}
	return nil
}

// Decode implements bin.Decoder.
func (s *SavedStarGift) Decode(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode savedStarGift#8983a452 to nil")
	}
	if err := b.ConsumeID(SavedStarGiftTypeID); err != nil {
		return fmt.Errorf("unable to decode savedStarGift#8983a452: %w", err)
	}
	return s.DecodeBare(b)
}

// DecodeBare implements bin.BareDecoder.
func (s *SavedStarGift) DecodeBare(b *bin.Buffer) error {
	if s == nil {
		return fmt.Errorf("can't decode savedStarGift#8983a452 to nil")
	}
	{
		if err := s.Flags.Decode(b); err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field flags: %w", err)
		}
	}
	s.NameHidden = s.Flags.Has(0)
	s.Unsaved = s.Flags.Has(5)
	s.Refunded = s.Flags.Has(9)
	s.CanUpgrade = s.Flags.Has(10)
	s.PinnedToTop = s.Flags.Has(12)
	s.UpgradeSeparate = s.Flags.Has(17)
	if s.Flags.Has(1) {
		value, err := DecodePeer(b)
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field from_id: %w", err)
		}
		s.FromID = value
	}
	{
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field date: %w", err)
		}
		s.Date = value
	}
	{
		value, err := DecodeStarGift(b)
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field gift: %w", err)
		}
		s.Gift = value
	}
	if s.Flags.Has(2) {
		if err := s.Message.Decode(b); err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field message: %w", err)
		}
	}
	if s.Flags.Has(3) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field msg_id: %w", err)
		}
		s.MsgID = value
	}
	if s.Flags.Has(11) {
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field saved_id: %w", err)
		}
		s.SavedID = value
	}
	if s.Flags.Has(4) {
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field convert_stars: %w", err)
		}
		s.ConvertStars = value
	}
	if s.Flags.Has(6) {
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field upgrade_stars: %w", err)
		}
		s.UpgradeStars = value
	}
	if s.Flags.Has(7) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field can_export_at: %w", err)
		}
		s.CanExportAt = value
	}
	if s.Flags.Has(8) {
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field transfer_stars: %w", err)
		}
		s.TransferStars = value
	}
	if s.Flags.Has(13) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field can_transfer_at: %w", err)
		}
		s.CanTransferAt = value
	}
	if s.Flags.Has(14) {
		value, err := b.Int()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field can_resell_at: %w", err)
		}
		s.CanResellAt = value
	}
	if s.Flags.Has(15) {
		headerLen, err := b.VectorHeader()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field collection_id: %w", err)
		}

		if headerLen > 0 {
			s.CollectionID = make([]int, 0, headerLen%bin.PreallocateLimit)
		}
		for idx := 0; idx < headerLen; idx++ {
			value, err := b.Int()
			if err != nil {
				return fmt.Errorf("unable to decode savedStarGift#8983a452: field collection_id: %w", err)
			}
			s.CollectionID = append(s.CollectionID, value)
		}
	}
	if s.Flags.Has(16) {
		value, err := b.String()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field prepaid_upgrade_hash: %w", err)
		}
		s.PrepaidUpgradeHash = value
	}
	if s.Flags.Has(18) {
		value, err := b.Long()
		if err != nil {
			return fmt.Errorf("unable to decode savedStarGift#8983a452: field drop_original_details_stars: %w", err)
		}
		s.DropOriginalDetailsStars = value
	}
	return nil
}

// SetNameHidden sets value of NameHidden conditional field.
func (s *SavedStarGift) SetNameHidden(value bool) {
	if value {
		s.Flags.Set(0)
		s.NameHidden = true
	} else {
		s.Flags.Unset(0)
		s.NameHidden = false
	}
}

// GetNameHidden returns value of NameHidden conditional field.
func (s *SavedStarGift) GetNameHidden() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(0)
}

// SetUnsaved sets value of Unsaved conditional field.
func (s *SavedStarGift) SetUnsaved(value bool) {
	if value {
		s.Flags.Set(5)
		s.Unsaved = true
	} else {
		s.Flags.Unset(5)
		s.Unsaved = false
	}
}

// GetUnsaved returns value of Unsaved conditional field.
func (s *SavedStarGift) GetUnsaved() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(5)
}

// SetRefunded sets value of Refunded conditional field.
func (s *SavedStarGift) SetRefunded(value bool) {
	if value {
		s.Flags.Set(9)
		s.Refunded = true
	} else {
		s.Flags.Unset(9)
		s.Refunded = false
	}
}

// GetRefunded returns value of Refunded conditional field.
func (s *SavedStarGift) GetRefunded() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(9)
}

// SetCanUpgrade sets value of CanUpgrade conditional field.
func (s *SavedStarGift) SetCanUpgrade(value bool) {
	if value {
		s.Flags.Set(10)
		s.CanUpgrade = true
	} else {
		s.Flags.Unset(10)
		s.CanUpgrade = false
	}
}

// GetCanUpgrade returns value of CanUpgrade conditional field.
func (s *SavedStarGift) GetCanUpgrade() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(10)
}

// SetPinnedToTop sets value of PinnedToTop conditional field.
func (s *SavedStarGift) SetPinnedToTop(value bool) {
	if value {
		s.Flags.Set(12)
		s.PinnedToTop = true
	} else {
		s.Flags.Unset(12)
		s.PinnedToTop = false
	}
}

// GetPinnedToTop returns value of PinnedToTop conditional field.
func (s *SavedStarGift) GetPinnedToTop() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(12)
}

// SetUpgradeSeparate sets value of UpgradeSeparate conditional field.
func (s *SavedStarGift) SetUpgradeSeparate(value bool) {
	if value {
		s.Flags.Set(17)
		s.UpgradeSeparate = true
	} else {
		s.Flags.Unset(17)
		s.UpgradeSeparate = false
	}
}

// GetUpgradeSeparate returns value of UpgradeSeparate conditional field.
func (s *SavedStarGift) GetUpgradeSeparate() (value bool) {
	if s == nil {
		return
	}
	return s.Flags.Has(17)
}

// SetFromID sets value of FromID conditional field.
func (s *SavedStarGift) SetFromID(value PeerClass) {
	s.Flags.Set(1)
	s.FromID = value
}

// GetFromID returns value of FromID conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetFromID() (value PeerClass, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(1) {
		return value, false
	}
	return s.FromID, true
}

// GetDate returns value of Date field.
func (s *SavedStarGift) GetDate() (value int) {
	if s == nil {
		return
	}
	return s.Date
}

// GetGift returns value of Gift field.
func (s *SavedStarGift) GetGift() (value StarGiftClass) {
	if s == nil {
		return
	}
	return s.Gift
}

// SetMessage sets value of Message conditional field.
func (s *SavedStarGift) SetMessage(value TextWithEntities) {
	s.Flags.Set(2)
	s.Message = value
}

// GetMessage returns value of Message conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetMessage() (value TextWithEntities, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(2) {
		return value, false
	}
	return s.Message, true
}

// SetMsgID sets value of MsgID conditional field.
func (s *SavedStarGift) SetMsgID(value int) {
	s.Flags.Set(3)
	s.MsgID = value
}

// GetMsgID returns value of MsgID conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetMsgID() (value int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(3) {
		return value, false
	}
	return s.MsgID, true
}

// SetSavedID sets value of SavedID conditional field.
func (s *SavedStarGift) SetSavedID(value int64) {
	s.Flags.Set(11)
	s.SavedID = value
}

// GetSavedID returns value of SavedID conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetSavedID() (value int64, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(11) {
		return value, false
	}
	return s.SavedID, true
}

// SetConvertStars sets value of ConvertStars conditional field.
func (s *SavedStarGift) SetConvertStars(value int64) {
	s.Flags.Set(4)
	s.ConvertStars = value
}

// GetConvertStars returns value of ConvertStars conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetConvertStars() (value int64, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(4) {
		return value, false
	}
	return s.ConvertStars, true
}

// SetUpgradeStars sets value of UpgradeStars conditional field.
func (s *SavedStarGift) SetUpgradeStars(value int64) {
	s.Flags.Set(6)
	s.UpgradeStars = value
}

// GetUpgradeStars returns value of UpgradeStars conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetUpgradeStars() (value int64, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(6) {
		return value, false
	}
	return s.UpgradeStars, true
}

// SetCanExportAt sets value of CanExportAt conditional field.
func (s *SavedStarGift) SetCanExportAt(value int) {
	s.Flags.Set(7)
	s.CanExportAt = value
}

// GetCanExportAt returns value of CanExportAt conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetCanExportAt() (value int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(7) {
		return value, false
	}
	return s.CanExportAt, true
}

// SetTransferStars sets value of TransferStars conditional field.
func (s *SavedStarGift) SetTransferStars(value int64) {
	s.Flags.Set(8)
	s.TransferStars = value
}

// GetTransferStars returns value of TransferStars conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetTransferStars() (value int64, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(8) {
		return value, false
	}
	return s.TransferStars, true
}

// SetCanTransferAt sets value of CanTransferAt conditional field.
func (s *SavedStarGift) SetCanTransferAt(value int) {
	s.Flags.Set(13)
	s.CanTransferAt = value
}

// GetCanTransferAt returns value of CanTransferAt conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetCanTransferAt() (value int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(13) {
		return value, false
	}
	return s.CanTransferAt, true
}

// SetCanResellAt sets value of CanResellAt conditional field.
func (s *SavedStarGift) SetCanResellAt(value int) {
	s.Flags.Set(14)
	s.CanResellAt = value
}

// GetCanResellAt returns value of CanResellAt conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetCanResellAt() (value int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(14) {
		return value, false
	}
	return s.CanResellAt, true
}

// SetCollectionID sets value of CollectionID conditional field.
func (s *SavedStarGift) SetCollectionID(value []int) {
	s.Flags.Set(15)
	s.CollectionID = value
}

// GetCollectionID returns value of CollectionID conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetCollectionID() (value []int, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(15) {
		return value, false
	}
	return s.CollectionID, true
}

// SetPrepaidUpgradeHash sets value of PrepaidUpgradeHash conditional field.
func (s *SavedStarGift) SetPrepaidUpgradeHash(value string) {
	s.Flags.Set(16)
	s.PrepaidUpgradeHash = value
}

// GetPrepaidUpgradeHash returns value of PrepaidUpgradeHash conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetPrepaidUpgradeHash() (value string, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(16) {
		return value, false
	}
	return s.PrepaidUpgradeHash, true
}

// SetDropOriginalDetailsStars sets value of DropOriginalDetailsStars conditional field.
func (s *SavedStarGift) SetDropOriginalDetailsStars(value int64) {
	s.Flags.Set(18)
	s.DropOriginalDetailsStars = value
}

// GetDropOriginalDetailsStars returns value of DropOriginalDetailsStars conditional field and
// boolean which is true if field was set.
func (s *SavedStarGift) GetDropOriginalDetailsStars() (value int64, ok bool) {
	if s == nil {
		return
	}
	if !s.Flags.Has(18) {
		return value, false
	}
	return s.DropOriginalDetailsStars, true
}
