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

// HelpAppUpdate represents TL type `help.appUpdate#ccbbce30`.
// An update is available for the application.
//
// See https://core.telegram.org/constructor/help.appUpdate for reference.
type HelpAppUpdate struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Unskippable, the new info must be shown to the user (with a popup or something else)
	CanNotSkip bool
	// Update ID
	ID int
	// New version name
	Version string
	// Text description of the update
	Text string
	// Message entities for styled text¹
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	Entities []MessageEntityClass
	// Application binary
	//
	// Use SetDocument and GetDocument helpers.
	Document DocumentClass
	// Application download URL
	//
	// Use SetURL and GetURL helpers.
	URL string
	// Associated sticker
	//
	// Use SetSticker and GetSticker helpers.
	Sticker DocumentClass
}

// HelpAppUpdateTypeID is TL type id of HelpAppUpdate.
const HelpAppUpdateTypeID = 0xccbbce30

// construct implements constructor of HelpAppUpdateClass.
func ( HelpAppUpdate) () HelpAppUpdateClass { return & }

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

	_ HelpAppUpdateClass = &HelpAppUpdate{}
)

func ( *HelpAppUpdate) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.CanNotSkip == false) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.Version == "") {
		return false
	}
	if !(.Text == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}
	if !(.Document == nil) {
		return false
	}
	if !(.URL == "") {
		return false
	}
	if !(.Sticker == nil) {
		return false
	}

	return true
}

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

// FillFrom fills HelpAppUpdate from given interface.
func ( *HelpAppUpdate) ( interface {
	() ( bool)
	() ( int)
	() ( string)
	() ( string)
	() ( []MessageEntityClass)
	() ( DocumentClass,  bool)
	() ( string,  bool)
	() ( DocumentClass,  bool)
}) {
	.CanNotSkip = .()
	.ID = .()
	.Version = .()
	.Text = .()
	.Entities = .()
	if ,  := .();  {
		.Document = 
	}

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *HelpAppUpdate) () tdp.Type {
	 := tdp.Type{
		Name: "help.appUpdate",
		ID:   HelpAppUpdateTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "CanNotSkip",
			SchemaName: "can_not_skip",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Version",
			SchemaName: "version",
		},
		{
			Name:       "Text",
			SchemaName: "text",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
		},
		{
			Name:       "Document",
			SchemaName: "document",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "URL",
			SchemaName: "url",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Sticker",
			SchemaName: "sticker",
			Null:       !.Flags.Has(3),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *HelpAppUpdate) () {
	if !(.CanNotSkip == false) {
		.Flags.Set(0)
	}
	if !(.Document == nil) {
		.Flags.Set(1)
	}
	if !(.URL == "") {
		.Flags.Set(2)
	}
	if !(.Sticker == nil) {
		.Flags.Set(3)
	}
}

// Encode implements bin.Encoder.
func ( *HelpAppUpdate) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.appUpdate#ccbbce30 as nil")
	}
	.PutID(HelpAppUpdateTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *HelpAppUpdate) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.appUpdate#ccbbce30 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode help.appUpdate#ccbbce30: field flags: %w", )
	}
	.PutInt(.ID)
	.PutString(.Version)
	.PutString(.Text)
	.PutVectorHeader(len(.Entities))
	for ,  := range .Entities {
		if  == nil {
			return fmt.Errorf("unable to encode help.appUpdate#ccbbce30: field entities element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode help.appUpdate#ccbbce30: field entities element with index %d: %w", , )
		}
	}
	if .Flags.Has(1) {
		if .Document == nil {
			return fmt.Errorf("unable to encode help.appUpdate#ccbbce30: field document is nil")
		}
		if  := .Document.Encode();  != nil {
			return fmt.Errorf("unable to encode help.appUpdate#ccbbce30: field document: %w", )
		}
	}
	if .Flags.Has(2) {
		.PutString(.URL)
	}
	if .Flags.Has(3) {
		if .Sticker == nil {
			return fmt.Errorf("unable to encode help.appUpdate#ccbbce30: field sticker is nil")
		}
		if  := .Sticker.Encode();  != nil {
			return fmt.Errorf("unable to encode help.appUpdate#ccbbce30: field sticker: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *HelpAppUpdate) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.appUpdate#ccbbce30 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field flags: %w", )
		}
	}
	.CanNotSkip = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field version: %w", )
		}
		.Version = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field text: %w", )
		}
		.Text = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field entities: %w", )
		}

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	if .Flags.Has(1) {
		,  := DecodeDocument()
		if  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field document: %w", )
		}
		.Document = 
	}
	if .Flags.Has(2) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field url: %w", )
		}
		.URL = 
	}
	if .Flags.Has(3) {
		,  := DecodeDocument()
		if  != nil {
			return fmt.Errorf("unable to decode help.appUpdate#ccbbce30: field sticker: %w", )
		}
		.Sticker = 
	}
	return nil
}

// SetCanNotSkip sets value of CanNotSkip conditional field.
func ( *HelpAppUpdate) ( bool) {
	if  {
		.Flags.Set(0)
		.CanNotSkip = true
	} else {
		.Flags.Unset(0)
		.CanNotSkip = false
	}
}

// GetCanNotSkip returns value of CanNotSkip conditional field.
func ( *HelpAppUpdate) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetID returns value of ID field.
func ( *HelpAppUpdate) () ( int) {
	if  == nil {
		return
	}
	return .ID
}

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

// GetText returns value of Text field.
func ( *HelpAppUpdate) () ( string) {
	if  == nil {
		return
	}
	return .Text
}

// GetEntities returns value of Entities field.
func ( *HelpAppUpdate) () ( []MessageEntityClass) {
	if  == nil {
		return
	}
	return .Entities
}

// SetDocument sets value of Document conditional field.
func ( *HelpAppUpdate) ( DocumentClass) {
	.Flags.Set(1)
	.Document = 
}

// GetDocument returns value of Document conditional field and
// boolean which is true if field was set.
func ( *HelpAppUpdate) () ( DocumentClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .Document, true
}

// SetURL sets value of URL conditional field.
func ( *HelpAppUpdate) ( string) {
	.Flags.Set(2)
	.URL = 
}

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

// SetSticker sets value of Sticker conditional field.
func ( *HelpAppUpdate) ( DocumentClass) {
	.Flags.Set(3)
	.Sticker = 
}

// GetSticker returns value of Sticker conditional field and
// boolean which is true if field was set.
func ( *HelpAppUpdate) () ( DocumentClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Sticker, true
}

// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func ( *HelpAppUpdate) () ( MessageEntityClassArray) {
	return MessageEntityClassArray(.Entities)
}

// HelpNoAppUpdate represents TL type `help.noAppUpdate#c45a6536`.
// No updates are available for the application.
//
// See https://core.telegram.org/constructor/help.noAppUpdate for reference.
type HelpNoAppUpdate struct {
}

// HelpNoAppUpdateTypeID is TL type id of HelpNoAppUpdate.
const HelpNoAppUpdateTypeID = 0xc45a6536

// construct implements constructor of HelpAppUpdateClass.
func ( HelpNoAppUpdate) () HelpAppUpdateClass { return & }

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

	_ HelpAppUpdateClass = &HelpNoAppUpdate{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func ( *HelpNoAppUpdate) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.noAppUpdate#c45a6536 as nil")
	}
	.PutID(HelpNoAppUpdateTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *HelpNoAppUpdate) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.noAppUpdate#c45a6536 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *HelpNoAppUpdate) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode help.noAppUpdate#c45a6536 to nil")
	}
	return nil
}

// HelpAppUpdateClassName is schema name of HelpAppUpdateClass.
const HelpAppUpdateClassName = "help.AppUpdate"

// HelpAppUpdateClass represents help.AppUpdate generic type.
//
// See https://core.telegram.org/type/help.AppUpdate for reference.
//
// Example:
//
//	g, err := tg.DecodeHelpAppUpdate(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.HelpAppUpdate: // help.appUpdate#ccbbce30
//	case *tg.HelpNoAppUpdate: // help.noAppUpdate#c45a6536
//	default: panic(v)
//	}
type HelpAppUpdateClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() HelpAppUpdateClass

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

// DecodeHelpAppUpdate implements binary de-serialization for HelpAppUpdateClass.
func ( *bin.Buffer) (HelpAppUpdateClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case HelpAppUpdateTypeID:
		// Decoding help.appUpdate#ccbbce30.
		 := HelpAppUpdate{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode HelpAppUpdateClass: %w", )
		}
		return &, nil
	case HelpNoAppUpdateTypeID:
		// Decoding help.noAppUpdate#c45a6536.
		 := HelpNoAppUpdate{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode HelpAppUpdateClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode HelpAppUpdateClass: %w", bin.NewUnexpectedID())
	}
}

// HelpAppUpdate boxes the HelpAppUpdateClass providing a helper.
type HelpAppUpdateBox struct {
	AppUpdate HelpAppUpdateClass
}

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

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