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

// HelpTermsOfService represents TL type `help.termsOfService#780a0310`.
// Info about the latest telegram Terms Of Service
//
// See https://core.telegram.org/constructor/help.termsOfService for reference.
type HelpTermsOfService struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether a prompt must be showed to the user, in order to accept the new terms.
	Popup bool
	// ID of the new terms
	ID DataJSON
	// Text of the new terms
	Text string
	// Message entities for styled text¹
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	Entities []MessageEntityClass
	// Minimum age required to sign up to telegram, the user must confirm that they is older
	// than the minimum age.
	//
	// Use SetMinAgeConfirm and GetMinAgeConfirm helpers.
	MinAgeConfirm int
}

// HelpTermsOfServiceTypeID is TL type id of HelpTermsOfService.
const HelpTermsOfServiceTypeID = 0x780a0310

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

func ( *HelpTermsOfService) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Popup == false) {
		return false
	}
	if !(.ID.Zero()) {
		return false
	}
	if !(.Text == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}
	if !(.MinAgeConfirm == 0) {
		return false
	}

	return true
}

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

// FillFrom fills HelpTermsOfService from given interface.
func ( *HelpTermsOfService) ( interface {
	() ( bool)
	() ( DataJSON)
	() ( string)
	() ( []MessageEntityClass)
	() ( int,  bool)
}) {
	.Popup = .()
	.ID = .()
	.Text = .()
	.Entities = .()
	if ,  := .();  {
		.MinAgeConfirm = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *HelpTermsOfService) () tdp.Type {
	 := tdp.Type{
		Name: "help.termsOfService",
		ID:   HelpTermsOfServiceTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Popup",
			SchemaName: "popup",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "Text",
			SchemaName: "text",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
		},
		{
			Name:       "MinAgeConfirm",
			SchemaName: "min_age_confirm",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *HelpTermsOfService) () {
	if !(.Popup == false) {
		.Flags.Set(0)
	}
	if !(.MinAgeConfirm == 0) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *HelpTermsOfService) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.termsOfService#780a0310 as nil")
	}
	.PutID(HelpTermsOfServiceTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *HelpTermsOfService) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode help.termsOfService#780a0310 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode help.termsOfService#780a0310: field flags: %w", )
	}
	if  := .ID.Encode();  != nil {
		return fmt.Errorf("unable to encode help.termsOfService#780a0310: field id: %w", )
	}
	.PutString(.Text)
	.PutVectorHeader(len(.Entities))
	for ,  := range .Entities {
		if  == nil {
			return fmt.Errorf("unable to encode help.termsOfService#780a0310: field entities element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode help.termsOfService#780a0310: field entities element with index %d: %w", , )
		}
	}
	if .Flags.Has(1) {
		.PutInt(.MinAgeConfirm)
	}
	return nil
}

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

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

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode help.termsOfService#780a0310: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode help.termsOfService#780a0310: field min_age_confirm: %w", )
		}
		.MinAgeConfirm = 
	}
	return nil
}

// SetPopup sets value of Popup conditional field.
func ( *HelpTermsOfService) ( bool) {
	if  {
		.Flags.Set(0)
		.Popup = true
	} else {
		.Flags.Unset(0)
		.Popup = false
	}
}

// GetPopup returns value of Popup conditional field.
func ( *HelpTermsOfService) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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

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

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

// SetMinAgeConfirm sets value of MinAgeConfirm conditional field.
func ( *HelpTermsOfService) ( int) {
	.Flags.Set(1)
	.MinAgeConfirm = 
}

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

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