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

// StarGiftAuctionStateNotModified represents TL type `starGiftAuctionStateNotModified#fe333952`.
// Returned only by auction methods (never by updates) if the passed version is equal to
// the remote auction »¹.version, meaning auction information hasn't changed over the
// locally cached version.
//
// Links:
//  1. https://core.telegram.org/api/auctions
//
// See https://core.telegram.org/constructor/starGiftAuctionStateNotModified for reference.
type StarGiftAuctionStateNotModified struct {
}

// StarGiftAuctionStateNotModifiedTypeID is TL type id of StarGiftAuctionStateNotModified.
const StarGiftAuctionStateNotModifiedTypeID = 0xfe333952

// construct implements constructor of StarGiftAuctionStateClass.
func ( StarGiftAuctionStateNotModified) () StarGiftAuctionStateClass { return & }

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

	_ StarGiftAuctionStateClass = &StarGiftAuctionStateNotModified{}
)

func ( *StarGiftAuctionStateNotModified) () bool {
	if  == nil {
		return true
	}

	return true
}

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

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

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

// TypeInfo returns info about TL type.
func ( *StarGiftAuctionStateNotModified) () tdp.Type {
	 := tdp.Type{
		Name: "starGiftAuctionStateNotModified",
		ID:   StarGiftAuctionStateNotModifiedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{}
	return 
}

// Encode implements bin.Encoder.
func ( *StarGiftAuctionStateNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionStateNotModified#fe333952 as nil")
	}
	.PutID(StarGiftAuctionStateNotModifiedTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarGiftAuctionStateNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionStateNotModified#fe333952 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StarGiftAuctionStateNotModified) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftAuctionStateNotModified#fe333952 to nil")
	}
	return nil
}

// StarGiftAuctionState represents TL type `starGiftAuctionState#771a4e66`.
// Represents an active or pending auction »¹.
//
// Links:
//  1. https://core.telegram.org/api/auctions
//
// See https://core.telegram.org/constructor/starGiftAuctionState for reference.
type StarGiftAuctionState struct {
	// Only apply incoming starGiftAuctionState¹ constructors if the received version is
	// bigger than the locally cached version.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGiftAuctionState
	Version int
	// UNIX timestamp indicating when the auction will start (or when it started, if it's in
	// the past).
	StartDate int
	// UNIX timestamp indicating when the auction will end
	EndDate int
	// Minumum allowed bid amount in Telegram Stars¹: only applicable if the user hasn't
	// made a bid yet, otherwise must be overridden to the value of
	// starGiftAuctionUserState².min_bid_amount (which will be set if and only if the user
	// already made a bid to this auction).
	//
	// Links:
	//  1) https://core.telegram.org/api/stars
	//  2) https://core.telegram.org/constructor/starGiftAuctionUserState
	MinBidAmount int64
	// Contains a sparse list of bids starting from the top bids, a more detailed description
	// is available in the docs¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/auctions
	BidLevels []AuctionBidLevel
	// User IDs of the top 3 bidders (the user¹ constructors will be returned as min²
	// constructors in the containing object).
	//
	// Links:
	//  1) https://core.telegram.org/constructor/user
	//  2) https://core.telegram.org/api/min
	TopBidders []int64
	// UNIX timestamp indicating when the current auction round will end, distributing
	// starGift¹.gifts_per_round gifts to the top starGift².gifts_per_round bidders.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGift
	//  2) https://core.telegram.org/constructor/starGift
	NextRoundAt int
	// The number of gifts that were distributed in the previous round (also used to compute
	// the approximated index of the gift that the current user will receive, last_gift_num +
	// approx_pos, see here »¹ for more info).
	//
	// Links:
	//  1) https://core.telegram.org/api/auctions
	LastGiftNum int
	// The remaining number of gifts that are yet to be distributed.
	GiftsLeft int
	// The current round number (starting from 1).
	CurrentRound int
	// The total number of rounds in this auction.
	TotalRounds int
	// Detailed round information.
	Rounds []StarGiftAuctionRoundClass
}

// StarGiftAuctionStateTypeID is TL type id of StarGiftAuctionState.
const StarGiftAuctionStateTypeID = 0x771a4e66

// construct implements constructor of StarGiftAuctionStateClass.
func ( StarGiftAuctionState) () StarGiftAuctionStateClass { return & }

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

	_ StarGiftAuctionStateClass = &StarGiftAuctionState{}
)

func ( *StarGiftAuctionState) () bool {
	if  == nil {
		return true
	}
	if !(.Version == 0) {
		return false
	}
	if !(.StartDate == 0) {
		return false
	}
	if !(.EndDate == 0) {
		return false
	}
	if !(.MinBidAmount == 0) {
		return false
	}
	if !(.BidLevels == nil) {
		return false
	}
	if !(.TopBidders == nil) {
		return false
	}
	if !(.NextRoundAt == 0) {
		return false
	}
	if !(.LastGiftNum == 0) {
		return false
	}
	if !(.GiftsLeft == 0) {
		return false
	}
	if !(.CurrentRound == 0) {
		return false
	}
	if !(.TotalRounds == 0) {
		return false
	}
	if !(.Rounds == nil) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAuctionState from given interface.
func ( *StarGiftAuctionState) ( interface {
	() ( int)
	() ( int)
	() ( int)
	() ( int64)
	() ( []AuctionBidLevel)
	() ( []int64)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( int)
	() ( []StarGiftAuctionRoundClass)
}) {
	.Version = .()
	.StartDate = .()
	.EndDate = .()
	.MinBidAmount = .()
	.BidLevels = .()
	.TopBidders = .()
	.NextRoundAt = .()
	.LastGiftNum = .()
	.GiftsLeft = .()
	.CurrentRound = .()
	.TotalRounds = .()
	.Rounds = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StarGiftAuctionState) () tdp.Type {
	 := tdp.Type{
		Name: "starGiftAuctionState",
		ID:   StarGiftAuctionStateTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Version",
			SchemaName: "version",
		},
		{
			Name:       "StartDate",
			SchemaName: "start_date",
		},
		{
			Name:       "EndDate",
			SchemaName: "end_date",
		},
		{
			Name:       "MinBidAmount",
			SchemaName: "min_bid_amount",
		},
		{
			Name:       "BidLevels",
			SchemaName: "bid_levels",
		},
		{
			Name:       "TopBidders",
			SchemaName: "top_bidders",
		},
		{
			Name:       "NextRoundAt",
			SchemaName: "next_round_at",
		},
		{
			Name:       "LastGiftNum",
			SchemaName: "last_gift_num",
		},
		{
			Name:       "GiftsLeft",
			SchemaName: "gifts_left",
		},
		{
			Name:       "CurrentRound",
			SchemaName: "current_round",
		},
		{
			Name:       "TotalRounds",
			SchemaName: "total_rounds",
		},
		{
			Name:       "Rounds",
			SchemaName: "rounds",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *StarGiftAuctionState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionState#771a4e66 as nil")
	}
	.PutID(StarGiftAuctionStateTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarGiftAuctionState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionState#771a4e66 as nil")
	}
	.PutInt(.Version)
	.PutInt(.StartDate)
	.PutInt(.EndDate)
	.PutLong(.MinBidAmount)
	.PutVectorHeader(len(.BidLevels))
	for ,  := range .BidLevels {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode starGiftAuctionState#771a4e66: field bid_levels element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.TopBidders))
	for ,  := range .TopBidders {
		.PutLong()
	}
	.PutInt(.NextRoundAt)
	.PutInt(.LastGiftNum)
	.PutInt(.GiftsLeft)
	.PutInt(.CurrentRound)
	.PutInt(.TotalRounds)
	.PutVectorHeader(len(.Rounds))
	for ,  := range .Rounds {
		if  == nil {
			return fmt.Errorf("unable to encode starGiftAuctionState#771a4e66: field rounds element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode starGiftAuctionState#771a4e66: field rounds element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *StarGiftAuctionState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftAuctionState#771a4e66 to nil")
	}
	if  := .ConsumeID(StarGiftAuctionStateTypeID);  != nil {
		return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StarGiftAuctionState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftAuctionState#771a4e66 to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field version: %w", )
		}
		.Version = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field start_date: %w", )
		}
		.StartDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field end_date: %w", )
		}
		.EndDate = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field min_bid_amount: %w", )
		}
		.MinBidAmount = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field bid_levels: %w", )
		}

		if  > 0 {
			.BidLevels = make([]AuctionBidLevel, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  AuctionBidLevel
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field bid_levels: %w", )
			}
			.BidLevels = append(.BidLevels, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field top_bidders: %w", )
		}

		if  > 0 {
			.TopBidders = make([]int64, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := .Long()
			if  != nil {
				return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field top_bidders: %w", )
			}
			.TopBidders = append(.TopBidders, )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field next_round_at: %w", )
		}
		.NextRoundAt = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field last_gift_num: %w", )
		}
		.LastGiftNum = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field gifts_left: %w", )
		}
		.GiftsLeft = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field current_round: %w", )
		}
		.CurrentRound = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field total_rounds: %w", )
		}
		.TotalRounds = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field rounds: %w", )
		}

		if  > 0 {
			.Rounds = make([]StarGiftAuctionRoundClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeStarGiftAuctionRound()
			if  != nil {
				return fmt.Errorf("unable to decode starGiftAuctionState#771a4e66: field rounds: %w", )
			}
			.Rounds = append(.Rounds, )
		}
	}
	return nil
}

// GetVersion returns value of Version field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .Version
}

// GetStartDate returns value of StartDate field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .StartDate
}

// GetEndDate returns value of EndDate field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .EndDate
}

// GetMinBidAmount returns value of MinBidAmount field.
func ( *StarGiftAuctionState) () ( int64) {
	if  == nil {
		return
	}
	return .MinBidAmount
}

// GetBidLevels returns value of BidLevels field.
func ( *StarGiftAuctionState) () ( []AuctionBidLevel) {
	if  == nil {
		return
	}
	return .BidLevels
}

// GetTopBidders returns value of TopBidders field.
func ( *StarGiftAuctionState) () ( []int64) {
	if  == nil {
		return
	}
	return .TopBidders
}

// GetNextRoundAt returns value of NextRoundAt field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .NextRoundAt
}

// GetLastGiftNum returns value of LastGiftNum field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .LastGiftNum
}

// GetGiftsLeft returns value of GiftsLeft field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .GiftsLeft
}

// GetCurrentRound returns value of CurrentRound field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .CurrentRound
}

// GetTotalRounds returns value of TotalRounds field.
func ( *StarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .TotalRounds
}

// GetRounds returns value of Rounds field.
func ( *StarGiftAuctionState) () ( []StarGiftAuctionRoundClass) {
	if  == nil {
		return
	}
	return .Rounds
}

// MapRounds returns field Rounds wrapped in StarGiftAuctionRoundClassArray helper.
func ( *StarGiftAuctionState) () ( StarGiftAuctionRoundClassArray) {
	return StarGiftAuctionRoundClassArray(.Rounds)
}

// StarGiftAuctionStateFinished represents TL type `starGiftAuctionStateFinished#972dabbf`.
// Represents a finished auction »¹.
//
// Links:
//  1. https://core.telegram.org/api/auctions
//
// See https://core.telegram.org/constructor/starGiftAuctionStateFinished for reference.
type StarGiftAuctionStateFinished struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// UNIX timestamp indicating when the auction started.
	StartDate int
	// UNIX timestamp indicating when the auction ended.
	EndDate int
	// Average price of distributed gifts.
	AveragePrice int64
	// Number of gifts from the auction currently being resold on Telegram: if set, when the
	// corresponding element is clicked in graphical clients, payments.getResaleStarGifts¹
	// should be invoked with the ID of the gift associated to this auction, see here »²
	// for more info.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getResaleStarGifts
	//  2) https://core.telegram.org/api/auctions
	//
	// Use SetListedCount and GetListedCount helpers.
	ListedCount int
	// Number of gifts from the auction currently being resold on Fragment¹.
	//
	// Links:
	//  1) https://fragment.com
	//
	// Use SetFragmentListedCount and GetFragmentListedCount helpers.
	FragmentListedCount int
	// Only set if fragment_listed_count is set. If set, when the corresponding element is
	// clicked in graphical clients, this URL should be opened.
	//
	// Use SetFragmentListedURL and GetFragmentListedURL helpers.
	FragmentListedURL string
}

// StarGiftAuctionStateFinishedTypeID is TL type id of StarGiftAuctionStateFinished.
const StarGiftAuctionStateFinishedTypeID = 0x972dabbf

// construct implements constructor of StarGiftAuctionStateClass.
func ( StarGiftAuctionStateFinished) () StarGiftAuctionStateClass { return & }

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

	_ StarGiftAuctionStateClass = &StarGiftAuctionStateFinished{}
)

func ( *StarGiftAuctionStateFinished) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.StartDate == 0) {
		return false
	}
	if !(.EndDate == 0) {
		return false
	}
	if !(.AveragePrice == 0) {
		return false
	}
	if !(.ListedCount == 0) {
		return false
	}
	if !(.FragmentListedCount == 0) {
		return false
	}
	if !(.FragmentListedURL == "") {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAuctionStateFinished from given interface.
func ( *StarGiftAuctionStateFinished) ( interface {
	() ( int)
	() ( int)
	() ( int64)
	() ( int,  bool)
	() ( int,  bool)
	() ( string,  bool)
}) {
	.StartDate = .()
	.EndDate = .()
	.AveragePrice = .()
	if ,  := .();  {
		.ListedCount = 
	}

	if ,  := .();  {
		.FragmentListedCount = 
	}

	if ,  := .();  {
		.FragmentListedURL = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *StarGiftAuctionStateFinished) () tdp.Type {
	 := tdp.Type{
		Name: "starGiftAuctionStateFinished",
		ID:   StarGiftAuctionStateFinishedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "StartDate",
			SchemaName: "start_date",
		},
		{
			Name:       "EndDate",
			SchemaName: "end_date",
		},
		{
			Name:       "AveragePrice",
			SchemaName: "average_price",
		},
		{
			Name:       "ListedCount",
			SchemaName: "listed_count",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "FragmentListedCount",
			SchemaName: "fragment_listed_count",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "FragmentListedURL",
			SchemaName: "fragment_listed_url",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StarGiftAuctionStateFinished) () {
	if !(.ListedCount == 0) {
		.Flags.Set(0)
	}
	if !(.FragmentListedCount == 0) {
		.Flags.Set(1)
	}
	if !(.FragmentListedURL == "") {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *StarGiftAuctionStateFinished) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionStateFinished#972dabbf as nil")
	}
	.PutID(StarGiftAuctionStateFinishedTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarGiftAuctionStateFinished) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionStateFinished#972dabbf as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starGiftAuctionStateFinished#972dabbf: field flags: %w", )
	}
	.PutInt(.StartDate)
	.PutInt(.EndDate)
	.PutLong(.AveragePrice)
	if .Flags.Has(0) {
		.PutInt(.ListedCount)
	}
	if .Flags.Has(1) {
		.PutInt(.FragmentListedCount)
	}
	if .Flags.Has(1) {
		.PutString(.FragmentListedURL)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *StarGiftAuctionStateFinished) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftAuctionStateFinished#972dabbf to nil")
	}
	if  := .ConsumeID(StarGiftAuctionStateFinishedTypeID);  != nil {
		return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *StarGiftAuctionStateFinished) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftAuctionStateFinished#972dabbf to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: field flags: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: field start_date: %w", )
		}
		.StartDate = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: field end_date: %w", )
		}
		.EndDate = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: field average_price: %w", )
		}
		.AveragePrice = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: field listed_count: %w", )
		}
		.ListedCount = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: field fragment_listed_count: %w", )
		}
		.FragmentListedCount = 
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionStateFinished#972dabbf: field fragment_listed_url: %w", )
		}
		.FragmentListedURL = 
	}
	return nil
}

// GetStartDate returns value of StartDate field.
func ( *StarGiftAuctionStateFinished) () ( int) {
	if  == nil {
		return
	}
	return .StartDate
}

// GetEndDate returns value of EndDate field.
func ( *StarGiftAuctionStateFinished) () ( int) {
	if  == nil {
		return
	}
	return .EndDate
}

// GetAveragePrice returns value of AveragePrice field.
func ( *StarGiftAuctionStateFinished) () ( int64) {
	if  == nil {
		return
	}
	return .AveragePrice
}

// SetListedCount sets value of ListedCount conditional field.
func ( *StarGiftAuctionStateFinished) ( int) {
	.Flags.Set(0)
	.ListedCount = 
}

// GetListedCount returns value of ListedCount conditional field and
// boolean which is true if field was set.
func ( *StarGiftAuctionStateFinished) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .ListedCount, true
}

// SetFragmentListedCount sets value of FragmentListedCount conditional field.
func ( *StarGiftAuctionStateFinished) ( int) {
	.Flags.Set(1)
	.FragmentListedCount = 
}

// GetFragmentListedCount returns value of FragmentListedCount conditional field and
// boolean which is true if field was set.
func ( *StarGiftAuctionStateFinished) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .FragmentListedCount, true
}

// SetFragmentListedURL sets value of FragmentListedURL conditional field.
func ( *StarGiftAuctionStateFinished) ( string) {
	.Flags.Set(1)
	.FragmentListedURL = 
}

// GetFragmentListedURL returns value of FragmentListedURL conditional field and
// boolean which is true if field was set.
func ( *StarGiftAuctionStateFinished) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .FragmentListedURL, true
}

// StarGiftAuctionStateClassName is schema name of StarGiftAuctionStateClass.
const StarGiftAuctionStateClassName = "StarGiftAuctionState"

// StarGiftAuctionStateClass represents StarGiftAuctionState generic type.
//
// See https://core.telegram.org/type/StarGiftAuctionState for reference.
//
// Constructors:
//   - [StarGiftAuctionStateNotModified]
//   - [StarGiftAuctionState]
//   - [StarGiftAuctionStateFinished]
//
// Example:
//
//	g, err := tg.DecodeStarGiftAuctionState(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.StarGiftAuctionStateNotModified: // starGiftAuctionStateNotModified#fe333952
//	case *tg.StarGiftAuctionState: // starGiftAuctionState#771a4e66
//	case *tg.StarGiftAuctionStateFinished: // starGiftAuctionStateFinished#972dabbf
//	default: panic(v)
//	}
type StarGiftAuctionStateClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StarGiftAuctionStateClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// AsModified tries to map StarGiftAuctionStateClass to ModifiedStarGiftAuctionState.
	AsModified() (ModifiedStarGiftAuctionState, bool)
}

// ModifiedStarGiftAuctionState represents Modified subset of StarGiftAuctionStateClass.
type ModifiedStarGiftAuctionState interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() StarGiftAuctionStateClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// UNIX timestamp indicating when the auction will start (or when it started, if it's in
	// the past).
	GetStartDate() (value int)

	// UNIX timestamp indicating when the auction will end
	GetEndDate() (value int)
}

// AsModified tries to map StarGiftAuctionStateNotModified to ModifiedStarGiftAuctionState.
func ( *StarGiftAuctionStateNotModified) () (ModifiedStarGiftAuctionState, bool) {
	,  := (StarGiftAuctionStateClass()).(ModifiedStarGiftAuctionState)
	return , 
}

// AsModified tries to map StarGiftAuctionState to ModifiedStarGiftAuctionState.
func ( *StarGiftAuctionState) () (ModifiedStarGiftAuctionState, bool) {
	,  := (StarGiftAuctionStateClass()).(ModifiedStarGiftAuctionState)
	return , 
}

// AsModified tries to map StarGiftAuctionStateFinished to ModifiedStarGiftAuctionState.
func ( *StarGiftAuctionStateFinished) () (ModifiedStarGiftAuctionState, bool) {
	,  := (StarGiftAuctionStateClass()).(ModifiedStarGiftAuctionState)
	return , 
}

// DecodeStarGiftAuctionState implements binary de-serialization for StarGiftAuctionStateClass.
func ( *bin.Buffer) (StarGiftAuctionStateClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case StarGiftAuctionStateNotModifiedTypeID:
		// Decoding starGiftAuctionStateNotModified#fe333952.
		 := StarGiftAuctionStateNotModified{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAuctionStateClass: %w", )
		}
		return &, nil
	case StarGiftAuctionStateTypeID:
		// Decoding starGiftAuctionState#771a4e66.
		 := StarGiftAuctionState{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAuctionStateClass: %w", )
		}
		return &, nil
	case StarGiftAuctionStateFinishedTypeID:
		// Decoding starGiftAuctionStateFinished#972dabbf.
		 := StarGiftAuctionStateFinished{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode StarGiftAuctionStateClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode StarGiftAuctionStateClass: %w", bin.NewUnexpectedID())
	}
}

// StarGiftAuctionState boxes the StarGiftAuctionStateClass providing a helper.
type StarGiftAuctionStateBox struct {
	StarGiftAuctionState StarGiftAuctionStateClass
}

// Decode implements bin.Decoder for StarGiftAuctionStateBox.
func ( *StarGiftAuctionStateBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode StarGiftAuctionStateBox to nil")
	}
	,  := DecodeStarGiftAuctionState()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.StarGiftAuctionState = 
	return nil
}

// Encode implements bin.Encode for StarGiftAuctionStateBox.
func ( *StarGiftAuctionStateBox) ( *bin.Buffer) error {
	if  == nil || .StarGiftAuctionState == nil {
		return fmt.Errorf("unable to encode StarGiftAuctionStateClass as nil")
	}
	return .StarGiftAuctionState.Encode()
}