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

// StarGiftAuctionUserState represents TL type `starGiftAuctionUserState#2eeed1c4`.
// Contains information about the current user's state in an auction »¹.
// The bid_amount, bid_date, bid_peer and min_bid_amount flags of
// starGiftAuctionUserState¹ will all be set if the user placed a bid in the auction.
//
// Links:
//  1. https://core.telegram.org/api/auctions
//  2. https://core.telegram.org/constructor/starGiftAuctionUserState
//
// See https://core.telegram.org/constructor/starGiftAuctionUserState for reference.
type StarGiftAuctionUserState struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// If set, the placed bid was returned to the user, because it was outbid so much that it
	// fell out of the top starGiftAuctionState¹.gifts_left positions, meaning that even if
	// no new bids are placed, the user will never receive any gifts, so the bid was
	// completely removed from the auction, and in order to participate again the user must
	// manually make a new bid.
	//
	// Links:
	//  1) https://core.telegram.org/constructor/starGiftAuctionState
	Returned bool
	// Contains the amount of the placed bid in Telegram Stars¹.
	//
	// Links:
	//  1) https://core.telegram.org/api/stars
	//
	// Use SetBidAmount and GetBidAmount helpers.
	BidAmount int64
	// Contains a UNIX timestamp, indicating when the bid was placed.
	//
	// Use SetBidDate and GetBidDate helpers.
	BidDate int
	// Contains the minumum allowed bid amount in Telegram Stars¹, if set overrides
	// starGiftAuctionState².min_bid_amount for the current user.
	//
	// Links:
	//  1) https://core.telegram.org/api/stars
	//  2) https://core.telegram.org/constructor/starGiftAuctionState
	//
	// Use SetMinBidAmount and GetMinBidAmount helpers.
	MinBidAmount int64
	// Contains the peer that will receive the gift, if you end up winning this round
	//
	// Use SetBidPeer and GetBidPeer helpers.
	BidPeer PeerClass
	// Contains the number of gifts that were purchased so far in the auction by the current
	// user.
	AcquiredCount int
}

// StarGiftAuctionUserStateTypeID is TL type id of StarGiftAuctionUserState.
const StarGiftAuctionUserStateTypeID = 0x2eeed1c4

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

func ( *StarGiftAuctionUserState) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Returned == false) {
		return false
	}
	if !(.BidAmount == 0) {
		return false
	}
	if !(.BidDate == 0) {
		return false
	}
	if !(.MinBidAmount == 0) {
		return false
	}
	if !(.BidPeer == nil) {
		return false
	}
	if !(.AcquiredCount == 0) {
		return false
	}

	return true
}

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

// FillFrom fills StarGiftAuctionUserState from given interface.
func ( *StarGiftAuctionUserState) ( interface {
	() ( bool)
	() ( int64,  bool)
	() ( int,  bool)
	() ( int64,  bool)
	() ( PeerClass,  bool)
	() ( int)
}) {
	.Returned = .()
	if ,  := .();  {
		.BidAmount = 
	}

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

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

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

	.AcquiredCount = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *StarGiftAuctionUserState) () tdp.Type {
	 := tdp.Type{
		Name: "starGiftAuctionUserState",
		ID:   StarGiftAuctionUserStateTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Returned",
			SchemaName: "returned",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "BidAmount",
			SchemaName: "bid_amount",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "BidDate",
			SchemaName: "bid_date",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "MinBidAmount",
			SchemaName: "min_bid_amount",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "BidPeer",
			SchemaName: "bid_peer",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "AcquiredCount",
			SchemaName: "acquired_count",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *StarGiftAuctionUserState) () {
	if !(.Returned == false) {
		.Flags.Set(1)
	}
	if !(.BidAmount == 0) {
		.Flags.Set(0)
	}
	if !(.BidDate == 0) {
		.Flags.Set(0)
	}
	if !(.MinBidAmount == 0) {
		.Flags.Set(0)
	}
	if !(.BidPeer == nil) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *StarGiftAuctionUserState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionUserState#2eeed1c4 as nil")
	}
	.PutID(StarGiftAuctionUserStateTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *StarGiftAuctionUserState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode starGiftAuctionUserState#2eeed1c4 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode starGiftAuctionUserState#2eeed1c4: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutLong(.BidAmount)
	}
	if .Flags.Has(0) {
		.PutInt(.BidDate)
	}
	if .Flags.Has(0) {
		.PutLong(.MinBidAmount)
	}
	if .Flags.Has(0) {
		if .BidPeer == nil {
			return fmt.Errorf("unable to encode starGiftAuctionUserState#2eeed1c4: field bid_peer is nil")
		}
		if  := .BidPeer.Encode();  != nil {
			return fmt.Errorf("unable to encode starGiftAuctionUserState#2eeed1c4: field bid_peer: %w", )
		}
	}
	.PutInt(.AcquiredCount)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *StarGiftAuctionUserState) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode starGiftAuctionUserState#2eeed1c4 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionUserState#2eeed1c4: field flags: %w", )
		}
	}
	.Returned = .Flags.Has(1)
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionUserState#2eeed1c4: field bid_amount: %w", )
		}
		.BidAmount = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionUserState#2eeed1c4: field bid_date: %w", )
		}
		.BidDate = 
	}
	if .Flags.Has(0) {
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionUserState#2eeed1c4: field min_bid_amount: %w", )
		}
		.MinBidAmount = 
	}
	if .Flags.Has(0) {
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionUserState#2eeed1c4: field bid_peer: %w", )
		}
		.BidPeer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode starGiftAuctionUserState#2eeed1c4: field acquired_count: %w", )
		}
		.AcquiredCount = 
	}
	return nil
}

// SetReturned sets value of Returned conditional field.
func ( *StarGiftAuctionUserState) ( bool) {
	if  {
		.Flags.Set(1)
		.Returned = true
	} else {
		.Flags.Unset(1)
		.Returned = false
	}
}

// GetReturned returns value of Returned conditional field.
func ( *StarGiftAuctionUserState) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetBidAmount sets value of BidAmount conditional field.
func ( *StarGiftAuctionUserState) ( int64) {
	.Flags.Set(0)
	.BidAmount = 
}

// GetBidAmount returns value of BidAmount conditional field and
// boolean which is true if field was set.
func ( *StarGiftAuctionUserState) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .BidAmount, true
}

// SetBidDate sets value of BidDate conditional field.
func ( *StarGiftAuctionUserState) ( int) {
	.Flags.Set(0)
	.BidDate = 
}

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

// SetMinBidAmount sets value of MinBidAmount conditional field.
func ( *StarGiftAuctionUserState) ( int64) {
	.Flags.Set(0)
	.MinBidAmount = 
}

// GetMinBidAmount returns value of MinBidAmount conditional field and
// boolean which is true if field was set.
func ( *StarGiftAuctionUserState) () ( int64,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .MinBidAmount, true
}

// SetBidPeer sets value of BidPeer conditional field.
func ( *StarGiftAuctionUserState) ( PeerClass) {
	.Flags.Set(0)
	.BidPeer = 
}

// GetBidPeer returns value of BidPeer conditional field and
// boolean which is true if field was set.
func ( *StarGiftAuctionUserState) () ( PeerClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .BidPeer, true
}

// GetAcquiredCount returns value of AcquiredCount field.
func ( *StarGiftAuctionUserState) () ( int) {
	if  == nil {
		return
	}
	return .AcquiredCount
}