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

// PaymentsStarGiftAuctionState represents TL type `payments.starGiftAuctionState#6b39f4ec`.
// Describes a collectible gift auction »¹.
//
// Links:
//  1. https://core.telegram.org/api/auctions
//
// See https://core.telegram.org/constructor/payments.starGiftAuctionState for reference.
type PaymentsStarGiftAuctionState struct {
	// The gift currently being distributed in the auction.
	Gift StarGiftClass
	// Auction state.
	State StarGiftAuctionStateClass
	// Auction state related to the current user (i.e. info about placed bids, won gifts, and
	// so on).
	UserState StarGiftAuctionUserState
	// Re-invoke the payments.getStarGiftAuctionState¹ method after timeout seconds to keep
	// receiving auction updates, see here »² for more info on the full flow.
	//
	// Links:
	//  1) https://core.telegram.org/method/payments.getStarGiftAuctionState
	//  2) https://core.telegram.org/api/auctions
	Timeout int
	// Mentioned users
	Users []UserClass
	// Mentioned chats
	Chats []ChatClass
}

// PaymentsStarGiftAuctionStateTypeID is TL type id of PaymentsStarGiftAuctionState.
const PaymentsStarGiftAuctionStateTypeID = 0x6b39f4ec

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

func ( *PaymentsStarGiftAuctionState) () bool {
	if  == nil {
		return true
	}
	if !(.Gift == nil) {
		return false
	}
	if !(.State == nil) {
		return false
	}
	if !(.UserState.Zero()) {
		return false
	}
	if !(.Timeout == 0) {
		return false
	}
	if !(.Users == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}

	return true
}

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

// FillFrom fills PaymentsStarGiftAuctionState from given interface.
func ( *PaymentsStarGiftAuctionState) ( interface {
	() ( StarGiftClass)
	() ( StarGiftAuctionStateClass)
	() ( StarGiftAuctionUserState)
	() ( int)
	() ( []UserClass)
	() ( []ChatClass)
}) {
	.Gift = .()
	.State = .()
	.UserState = .()
	.Timeout = .()
	.Users = .()
	.Chats = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *PaymentsStarGiftAuctionState) () tdp.Type {
	 := tdp.Type{
		Name: "payments.starGiftAuctionState",
		ID:   PaymentsStarGiftAuctionStateTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Gift",
			SchemaName: "gift",
		},
		{
			Name:       "State",
			SchemaName: "state",
		},
		{
			Name:       "UserState",
			SchemaName: "user_state",
		},
		{
			Name:       "Timeout",
			SchemaName: "timeout",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *PaymentsStarGiftAuctionState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.starGiftAuctionState#6b39f4ec as nil")
	}
	.PutID(PaymentsStarGiftAuctionStateTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *PaymentsStarGiftAuctionState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode payments.starGiftAuctionState#6b39f4ec as nil")
	}
	if .Gift == nil {
		return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field gift is nil")
	}
	if  := .Gift.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field gift: %w", )
	}
	if .State == nil {
		return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field state is nil")
	}
	if  := .State.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field state: %w", )
	}
	if  := .UserState.Encode();  != nil {
		return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field user_state: %w", )
	}
	.PutInt(.Timeout)
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field users element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode payments.starGiftAuctionState#6b39f4ec: field chats element with index %d: %w", , )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *PaymentsStarGiftAuctionState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode payments.starGiftAuctionState#6b39f4ec to nil")
	}
	{
		,  := DecodeStarGift()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field gift: %w", )
		}
		.Gift = 
	}
	{
		,  := DecodeStarGiftAuctionState()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field state: %w", )
		}
		.State = 
	}
	{
		if  := .UserState.Decode();  != nil {
			return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field user_state: %w", )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field timeout: %w", )
		}
		.Timeout = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode payments.starGiftAuctionState#6b39f4ec: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	return nil
}

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

// GetState returns value of State field.
func ( *PaymentsStarGiftAuctionState) () ( StarGiftAuctionStateClass) {
	if  == nil {
		return
	}
	return .State
}

// GetUserState returns value of UserState field.
func ( *PaymentsStarGiftAuctionState) () ( StarGiftAuctionUserState) {
	if  == nil {
		return
	}
	return .UserState
}

// GetTimeout returns value of Timeout field.
func ( *PaymentsStarGiftAuctionState) () ( int) {
	if  == nil {
		return
	}
	return .Timeout
}

// GetUsers returns value of Users field.
func ( *PaymentsStarGiftAuctionState) () ( []UserClass) {
	if  == nil {
		return
	}
	return .Users
}

// GetChats returns value of Chats field.
func ( *PaymentsStarGiftAuctionState) () ( []ChatClass) {
	if  == nil {
		return
	}
	return .Chats
}

// GetStateAsModified returns mapped value of State field.
func ( *PaymentsStarGiftAuctionState) () (ModifiedStarGiftAuctionState, bool) {
	return .State.AsModified()
}

// MapUsers returns field Users wrapped in UserClassArray helper.
func ( *PaymentsStarGiftAuctionState) () ( UserClassArray) {
	return UserClassArray(.Users)
}

// MapChats returns field Chats wrapped in ChatClassArray helper.
func ( *PaymentsStarGiftAuctionState) () ( ChatClassArray) {
	return ChatClassArray(.Chats)
}