// Code generated by gotdgen, DO NOT EDIT.

package tg

import (
	
	
	
	
	

	

	
	
	
	
)

// 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{}
)

// StarGiftCollection represents TL type `starGiftCollection#9d6b13b0`.
// Represents a star gift collection »¹.
//
// Links:
//  1. https://core.telegram.org/api/gifts#gift-collections
//
// See https://core.telegram.org/constructor/starGiftCollection for reference.
type StarGiftCollection struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// The ID of the collection.
	CollectionID int
	// Title of the collection.
	Title string
	// Optional icon for the collection, taken from the first gift in the collection.
	//
	// Use SetIcon and GetIcon helpers.
	Icon DocumentClass
	// Number of gifts in the collection.
	GiftsCount int
	// Field to use instead of collection_id when generating the hash to pass to payments
	// getStarGiftCollections¹.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getStarGiftCollections
	Hash int64
}

// StarGiftCollectionTypeID is TL type id of StarGiftCollection.
const StarGiftCollectionTypeID = 0x9d6b13b0

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

func ( *StarGiftCollection) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.CollectionID == 0) {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.Icon == nil) {
		return false
	}
	if !(.GiftsCount == 0) {
		return false
	}
	if !(.Hash == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftCollection from given interface.
func ( *StarGiftCollection) ( interface {
	() ( int)
	() ( string)
	() ( DocumentClass,  bool)
	() ( int)
	() ( int64)
}) {
	.CollectionID = .()
	.Title = .()
	if ,  := .();  {
		.Icon = 
	}

	.GiftsCount = .()
	.Hash = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StarGiftCollection) () tdp.Type {
	 := tdp.Type{
		Name: "starGiftCollection",
		ID:   StarGiftCollectionTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "CollectionID",
			SchemaName: "collection_id",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "Icon",
			SchemaName: "icon",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "GiftsCount",
			SchemaName: "gifts_count",
		},
		{
			Name:       "Hash",
			SchemaName: "hash",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StarGiftCollection) () {
	if !(.Icon == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *StarGiftCollection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftCollection#9d6b13b0 as nil")
	}
	.PutID(StarGiftCollectionTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarGiftCollection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftCollection#9d6b13b0 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starGiftCollection#9d6b13b0: field flags: %w", )
	}
	.PutInt(.CollectionID)
	.PutString(.Title)
	if .Flags.Has(0) {
		if .Icon == nil {
			return fmt.Errorf("unable to encode starGiftCollection#9d6b13b0: field icon is nil")
		}
		if  := .Icon.Encode();  != nil {
			return fmt.Errorf("unable to encode starGiftCollection#9d6b13b0: field icon: %w", )
		}
	}
	.PutInt(.GiftsCount)
	.PutLong(.Hash)
	return nil
}

// Decode implements bin.Decoder.
func ( *StarGiftCollection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftCollection#9d6b13b0 to nil")
	}
	if  := .ConsumeID(StarGiftCollectionTypeID);  != nil {
		return fmt.Errorf("unable to decode starGiftCollection#9d6b13b0: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StarGiftCollection) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftCollection#9d6b13b0 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starGiftCollection#9d6b13b0: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftCollection#9d6b13b0: field collection_id: %w", )
		}
		.CollectionID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftCollection#9d6b13b0: field title: %w", )
		}
		.Title = 
	}
	if .Flags.Has(0) {
		,  := DecodeDocument()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftCollection#9d6b13b0: field icon: %w", )
		}
		.Icon = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftCollection#9d6b13b0: field gifts_count: %w", )
		}
		.GiftsCount = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftCollection#9d6b13b0: field hash: %w", )
		}
		.Hash = 
	}
	return nil
}

// GetCollectionID returns value of CollectionID field.
func ( *StarGiftCollection) () ( int) {
	if  == nil {
		return
	}
	return .CollectionID
}

// GetTitle returns value of Title field.
func ( *StarGiftCollection) () ( string) {
	if  == nil {
		return
	}
	return .Title
}

// SetIcon sets value of Icon conditional field.
func ( *StarGiftCollection) ( DocumentClass) {
	.Flags.Set(0)
	.Icon = 
}

// GetIcon returns value of Icon conditional field and
// boolean which is true if field was set.
func ( *StarGiftCollection) () ( DocumentClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Icon, true
}

// GetGiftsCount returns value of GiftsCount field.
func ( *StarGiftCollection) () ( int) {
	if  == nil {
		return
	}
	return .GiftsCount
}

// GetHash returns value of Hash field.
func ( *StarGiftCollection) () ( int64) {
	if  == nil {
		return
	}
	return .Hash
}

// GetIconAsNotEmpty returns mapped value of Icon conditional field and
// boolean which is true if field was set.
func ( *StarGiftCollection) () (*Document, bool) {
	if ,  := .GetIcon();  {
		return .AsNotEmpty()
	}
	return nil, false
}