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

// HelpPromoDataEmpty represents TL type `help.promoDataEmpty#98f6ac75`.
// No PSA/MTProxy info is available
//
// See https://core.telegram.org/constructor/help.promoDataEmpty for reference.
type HelpPromoDataEmpty struct {
	// Re-fetch PSA/MTProxy info after the specified number of seconds
	Expires int
}

// HelpPromoDataEmptyTypeID is TL type id of HelpPromoDataEmpty.
const HelpPromoDataEmptyTypeID = 0x98f6ac75

// construct implements constructor of HelpPromoDataClass.
func ( HelpPromoDataEmpty) () HelpPromoDataClass { return & }

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

	_ HelpPromoDataClass = &HelpPromoDataEmpty{}
)

func ( *HelpPromoDataEmpty) () bool {
	if  == nil {
		return true
	}
	if !(.Expires == 0) {
		return false
	}

	return true
}

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

// FillFrom fills HelpPromoDataEmpty from given interface.
func ( *HelpPromoDataEmpty) ( interface {
	() ( int)
}) {
	.Expires = .()
}

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

// TypeName returns name of type in TL schema.
func (*HelpPromoDataEmpty) () string {
	return "help.promoDataEmpty"
}

// TypeInfo returns info about TL type.
func ( *HelpPromoDataEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "help.promoDataEmpty",
		ID:   HelpPromoDataEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Expires",
			SchemaName: "expires",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *HelpPromoDataEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.promoDataEmpty#98f6ac75 as nil")
	}
	.PutID(HelpPromoDataEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *HelpPromoDataEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.promoDataEmpty#98f6ac75 as nil")
	}
	.PutInt(.Expires)
	return nil
}

// Decode implements bin.Decoder.
func ( *HelpPromoDataEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.promoDataEmpty#98f6ac75 to nil")
	}
	if  := .ConsumeID(HelpPromoDataEmptyTypeID);  != nil {
		return fmt.Errorf("unable to decode help.promoDataEmpty#98f6ac75: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *HelpPromoDataEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.promoDataEmpty#98f6ac75 to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode help.promoDataEmpty#98f6ac75: field expires: %w", )
		}
		.Expires = 
	}
	return nil
}

// GetExpires returns value of Expires field.
func ( *HelpPromoDataEmpty) () ( int) {
	if  == nil {
		return
	}
	return .Expires
}

// HelpPromoData represents TL type `help.promoData#8c39793f`.
// MTProxy/Public Service Announcement information
//
// See https://core.telegram.org/constructor/help.promoData for reference.
type HelpPromoData struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// MTProxy-related channel
	Proxy bool
	// Expiry of PSA/MTProxy info
	Expires int
	// MTProxy/PSA peer
	Peer PeerClass
	// Chat info
	Chats []ChatClass
	// User info
	Users []UserClass
	// PSA type
	//
	// Use SetPsaType and GetPsaType helpers.
	PsaType string
	// PSA message
	//
	// Use SetPsaMessage and GetPsaMessage helpers.
	PsaMessage string
}

// HelpPromoDataTypeID is TL type id of HelpPromoData.
const HelpPromoDataTypeID = 0x8c39793f

// construct implements constructor of HelpPromoDataClass.
func ( HelpPromoData) () HelpPromoDataClass { return & }

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

	_ HelpPromoDataClass = &HelpPromoData{}
)

func ( *HelpPromoData) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Proxy == false) {
		return false
	}
	if !(.Expires == 0) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}
	if !(.PsaType == "") {
		return false
	}
	if !(.PsaMessage == "") {
		return false
	}

	return true
}

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

// FillFrom fills HelpPromoData from given interface.
func ( *HelpPromoData) ( interface {
	() ( bool)
	() ( int)
	() ( PeerClass)
	() ( []ChatClass)
	() ( []UserClass)
	() ( string,  bool)
	() ( string,  bool)
}) {
	.Proxy = .()
	.Expires = .()
	.Peer = .()
	.Chats = .()
	.Users = .()
	if ,  := .();  {
		.PsaType = 
	}

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

}

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

// TypeName returns name of type in TL schema.
func (*HelpPromoData) () string {
	return "help.promoData"
}

// TypeInfo returns info about TL type.
func ( *HelpPromoData) () tdp.Type {
	 := tdp.Type{
		Name: "help.promoData",
		ID:   HelpPromoDataTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Proxy",
			SchemaName: "proxy",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Expires",
			SchemaName: "expires",
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "PsaType",
			SchemaName: "psa_type",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PsaMessage",
			SchemaName: "psa_message",
			Null:       !.Flags.Has(2),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *HelpPromoData) () {
	if !(.Proxy == false) {
		.Flags.Set(0)
	}
	if !(.PsaType == "") {
		.Flags.Set(1)
	}
	if !(.PsaMessage == "") {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *HelpPromoData) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.promoData#8c39793f as nil")
	}
	.PutID(HelpPromoDataTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *HelpPromoData) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.promoData#8c39793f as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode help.promoData#8c39793f: field flags: %w", )
	}
	.PutInt(.Expires)
	if .Peer == nil {
		return fmt.Errorf("unable to encode help.promoData#8c39793f: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode help.promoData#8c39793f: field peer: %w", )
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode help.promoData#8c39793f: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode help.promoData#8c39793f: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode help.promoData#8c39793f: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode help.promoData#8c39793f: field users element with index %d: %w", , )
		}
	}
	if .Flags.Has(1) {
		.PutString(.PsaType)
	}
	if .Flags.Has(2) {
		.PutString(.PsaMessage)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *HelpPromoData) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.promoData#8c39793f to nil")
	}
	if  := .ConsumeID(HelpPromoDataTypeID);  != nil {
		return fmt.Errorf("unable to decode help.promoData#8c39793f: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *HelpPromoData) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.promoData#8c39793f to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode help.promoData#8c39793f: field flags: %w", )
		}
	}
	.Proxy = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode help.promoData#8c39793f: field expires: %w", )
		}
		.Expires = 
	}
	{
		,  := DecodePeer()
		if  != nil {
			return fmt.Errorf("unable to decode help.promoData#8c39793f: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode help.promoData#8c39793f: field chats: %w", )
		}

		if  > 0 {
			.Chats = make([]ChatClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeChat()
			if  != nil {
				return fmt.Errorf("unable to decode help.promoData#8c39793f: field chats: %w", )
			}
			.Chats = append(.Chats, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode help.promoData#8c39793f: field users: %w", )
		}

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode help.promoData#8c39793f: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	if .Flags.Has(1) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.promoData#8c39793f: field psa_type: %w", )
		}
		.PsaType = 
	}
	if .Flags.Has(2) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.promoData#8c39793f: field psa_message: %w", )
		}
		.PsaMessage = 
	}
	return nil
}

// SetProxy sets value of Proxy conditional field.
func ( *HelpPromoData) ( bool) {
	if  {
		.Flags.Set(0)
		.Proxy = true
	} else {
		.Flags.Unset(0)
		.Proxy = false
	}
}

// GetProxy returns value of Proxy conditional field.
func ( *HelpPromoData) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetExpires returns value of Expires field.
func ( *HelpPromoData) () ( int) {
	if  == nil {
		return
	}
	return .Expires
}

// GetPeer returns value of Peer field.
func ( *HelpPromoData) () ( PeerClass) {
	if  == nil {
		return
	}
	return .Peer
}

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

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

// SetPsaType sets value of PsaType conditional field.
func ( *HelpPromoData) ( string) {
	.Flags.Set(1)
	.PsaType = 
}

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

// SetPsaMessage sets value of PsaMessage conditional field.
func ( *HelpPromoData) ( string) {
	.Flags.Set(2)
	.PsaMessage = 
}

// GetPsaMessage returns value of PsaMessage conditional field and
// boolean which is true if field was set.
func ( *HelpPromoData) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .PsaMessage, true
}

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

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

// HelpPromoDataClassName is schema name of HelpPromoDataClass.
const HelpPromoDataClassName = "help.PromoData"

// HelpPromoDataClass represents help.PromoData generic type.
//
// See https://core.telegram.org/type/help.PromoData for reference.
//
// Example:
//
//	g, err := tg.DecodeHelpPromoData(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.HelpPromoDataEmpty: // help.promoDataEmpty#98f6ac75
//	case *tg.HelpPromoData: // help.promoData#8c39793f
//	default: panic(v)
//	}
type HelpPromoDataClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() HelpPromoDataClass

	// 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

	// Re-fetch PSA/MTProxy info after the specified number of seconds
	GetExpires() (value int)

	// AsNotEmpty tries to map HelpPromoDataClass to HelpPromoData.
	AsNotEmpty() (*HelpPromoData, bool)
}

// AsNotEmpty tries to map HelpPromoDataEmpty to HelpPromoData.
func ( *HelpPromoDataEmpty) () (*HelpPromoData, bool) {
	return nil, false
}

// AsNotEmpty tries to map HelpPromoData to HelpPromoData.
func ( *HelpPromoData) () (*HelpPromoData, bool) {
	return , true
}

// DecodeHelpPromoData implements binary de-serialization for HelpPromoDataClass.
func ( *bin.Buffer) (HelpPromoDataClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case HelpPromoDataEmptyTypeID:
		// Decoding help.promoDataEmpty#98f6ac75.
		 := HelpPromoDataEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode HelpPromoDataClass: %w", )
		}
		return &, nil
	case HelpPromoDataTypeID:
		// Decoding help.promoData#8c39793f.
		 := HelpPromoData{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode HelpPromoDataClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode HelpPromoDataClass: %w", bin.NewUnexpectedID())
	}
}

// HelpPromoData boxes the HelpPromoDataClass providing a helper.
type HelpPromoDataBox struct {
	PromoData HelpPromoDataClass
}

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

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