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

// UpdatesChannelDifferenceEmpty represents TL type `updates.channelDifferenceEmpty#3e11affb`.
// There are no new updates
//
// See https://core.telegram.org/constructor/updates.channelDifferenceEmpty for reference.
type UpdatesChannelDifferenceEmpty struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether there are more updates that must be fetched (always false)
	Final bool
	// The latest PTSĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/api/updates
	Pts int
	// Clients are supposed to refetch the channel difference after timeout seconds have
	// elapsed
	//
	// Use SetTimeout and GetTimeout helpers.
	Timeout int
}

// UpdatesChannelDifferenceEmptyTypeID is TL type id of UpdatesChannelDifferenceEmpty.
const UpdatesChannelDifferenceEmptyTypeID = 0x3e11affb

// construct implements constructor of UpdatesChannelDifferenceClass.
func ( UpdatesChannelDifferenceEmpty) () UpdatesChannelDifferenceClass { return & }

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

	_ UpdatesChannelDifferenceClass = &UpdatesChannelDifferenceEmpty{}
)

func ( *UpdatesChannelDifferenceEmpty) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Final == false) {
		return false
	}
	if !(.Pts == 0) {
		return false
	}
	if !(.Timeout == 0) {
		return false
	}

	return true
}

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

// FillFrom fills UpdatesChannelDifferenceEmpty from given interface.
func ( *UpdatesChannelDifferenceEmpty) ( interface {
	() ( bool)
	() ( int)
	() ( int,  bool)
}) {
	.Final = .()
	.Pts = .()
	if ,  := .();  {
		.Timeout = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*UpdatesChannelDifferenceEmpty) () string {
	return "updates.channelDifferenceEmpty"
}

// TypeInfo returns info about TL type.
func ( *UpdatesChannelDifferenceEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "updates.channelDifferenceEmpty",
		ID:   UpdatesChannelDifferenceEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Final",
			SchemaName: "final",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Pts",
			SchemaName: "pts",
		},
		{
			Name:       "Timeout",
			SchemaName: "timeout",
			Null:       !.Flags.Has(1),
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *UpdatesChannelDifferenceEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode updates.channelDifferenceEmpty#3e11affb as nil")
	}
	.PutID(UpdatesChannelDifferenceEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UpdatesChannelDifferenceEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode updates.channelDifferenceEmpty#3e11affb as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode updates.channelDifferenceEmpty#3e11affb: field flags: %w", )
	}
	.PutInt(.Pts)
	if .Flags.Has(1) {
		.PutInt(.Timeout)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *UpdatesChannelDifferenceEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode updates.channelDifferenceEmpty#3e11affb to nil")
	}
	if  := .ConsumeID(UpdatesChannelDifferenceEmptyTypeID);  != nil {
		return fmt.Errorf("unable to decode updates.channelDifferenceEmpty#3e11affb: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *UpdatesChannelDifferenceEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode updates.channelDifferenceEmpty#3e11affb to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceEmpty#3e11affb: field flags: %w", )
		}
	}
	.Final = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceEmpty#3e11affb: field pts: %w", )
		}
		.Pts = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceEmpty#3e11affb: field timeout: %w", )
		}
		.Timeout = 
	}
	return nil
}

// SetFinal sets value of Final conditional field.
func ( *UpdatesChannelDifferenceEmpty) ( bool) {
	if  {
		.Flags.Set(0)
		.Final = true
	} else {
		.Flags.Unset(0)
		.Final = false
	}
}

// GetFinal returns value of Final conditional field.
func ( *UpdatesChannelDifferenceEmpty) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetPts returns value of Pts field.
func ( *UpdatesChannelDifferenceEmpty) () ( int) {
	if  == nil {
		return
	}
	return .Pts
}

// SetTimeout sets value of Timeout conditional field.
func ( *UpdatesChannelDifferenceEmpty) ( int) {
	.Flags.Set(1)
	.Timeout = 
}

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

// UpdatesChannelDifferenceTooLong represents TL type `updates.channelDifferenceTooLong#a4bcc6fe`.
// The provided pts + limit < remote pts. Simply, there are too many updates to be
// fetched (more than limit), the client has to resolve the update gap in one of the
// following ways (assuming the existence of a persistent database to locally store
// messages):
// It should be also noted that some messages like live location messages shouldn't be
// deleted.
//
// See https://core.telegram.org/constructor/updates.channelDifferenceTooLong for reference.
type UpdatesChannelDifferenceTooLong struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether there are more updates that must be fetched (always false)
	Final bool
	// Clients are supposed to refetch the channel difference after timeout seconds have
	// elapsed
	//
	// Use SetTimeout and GetTimeout helpers.
	Timeout int
	// Dialog containing the latest PTSĀ¹ that can be used to reset the channel state
	//
	// Links:
	//  1) https://core.telegram.org/api/updates
	Dialog DialogClass
	// The latest messages
	Messages []MessageClass
	// Chats from messages
	Chats []ChatClass
	// Users from messages
	Users []UserClass
}

// UpdatesChannelDifferenceTooLongTypeID is TL type id of UpdatesChannelDifferenceTooLong.
const UpdatesChannelDifferenceTooLongTypeID = 0xa4bcc6fe

// construct implements constructor of UpdatesChannelDifferenceClass.
func ( UpdatesChannelDifferenceTooLong) () UpdatesChannelDifferenceClass { return & }

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

	_ UpdatesChannelDifferenceClass = &UpdatesChannelDifferenceTooLong{}
)

func ( *UpdatesChannelDifferenceTooLong) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Final == false) {
		return false
	}
	if !(.Timeout == 0) {
		return false
	}
	if !(.Dialog == nil) {
		return false
	}
	if !(.Messages == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills UpdatesChannelDifferenceTooLong from given interface.
func ( *UpdatesChannelDifferenceTooLong) ( interface {
	() ( bool)
	() ( int,  bool)
	() ( DialogClass)
	() ( []MessageClass)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Final = .()
	if ,  := .();  {
		.Timeout = 
	}

	.Dialog = .()
	.Messages = .()
	.Chats = .()
	.Users = .()
}

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

// TypeName returns name of type in TL schema.
func (*UpdatesChannelDifferenceTooLong) () string {
	return "updates.channelDifferenceTooLong"
}

// TypeInfo returns info about TL type.
func ( *UpdatesChannelDifferenceTooLong) () tdp.Type {
	 := tdp.Type{
		Name: "updates.channelDifferenceTooLong",
		ID:   UpdatesChannelDifferenceTooLongTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Final",
			SchemaName: "final",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Timeout",
			SchemaName: "timeout",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Dialog",
			SchemaName: "dialog",
		},
		{
			Name:       "Messages",
			SchemaName: "messages",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *UpdatesChannelDifferenceTooLong) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode updates.channelDifferenceTooLong#a4bcc6fe as nil")
	}
	.PutID(UpdatesChannelDifferenceTooLongTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UpdatesChannelDifferenceTooLong) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode updates.channelDifferenceTooLong#a4bcc6fe as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field flags: %w", )
	}
	if .Flags.Has(1) {
		.PutInt(.Timeout)
	}
	if .Dialog == nil {
		return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field dialog is nil")
	}
	if  := .Dialog.Encode();  != nil {
		return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field dialog: %w", )
	}
	.PutVectorHeader(len(.Messages))
	for ,  := range .Messages {
		if  == nil {
			return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field messages element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field messages element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode updates.channelDifferenceTooLong#a4bcc6fe: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *UpdatesChannelDifferenceTooLong) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode updates.channelDifferenceTooLong#a4bcc6fe to nil")
	}
	if  := .ConsumeID(UpdatesChannelDifferenceTooLongTypeID);  != nil {
		return fmt.Errorf("unable to decode updates.channelDifferenceTooLong#a4bcc6fe: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *UpdatesChannelDifferenceTooLong) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode updates.channelDifferenceTooLong#a4bcc6fe to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceTooLong#a4bcc6fe: field flags: %w", )
		}
	}
	.Final = .Flags.Has(0)
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceTooLong#a4bcc6fe: field timeout: %w", )
		}
		.Timeout = 
	}
	{
		,  := DecodeDialog()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceTooLong#a4bcc6fe: field dialog: %w", )
		}
		.Dialog = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceTooLong#a4bcc6fe: field messages: %w", )
		}

		if  > 0 {
			.Messages = make([]MessageClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessage()
			if  != nil {
				return fmt.Errorf("unable to decode updates.channelDifferenceTooLong#a4bcc6fe: field messages: %w", )
			}
			.Messages = append(.Messages, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifferenceTooLong#a4bcc6fe: field chats: %w", )
		}

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

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

// SetFinal sets value of Final conditional field.
func ( *UpdatesChannelDifferenceTooLong) ( bool) {
	if  {
		.Flags.Set(0)
		.Final = true
	} else {
		.Flags.Unset(0)
		.Final = false
	}
}

// GetFinal returns value of Final conditional field.
func ( *UpdatesChannelDifferenceTooLong) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetTimeout sets value of Timeout conditional field.
func ( *UpdatesChannelDifferenceTooLong) ( int) {
	.Flags.Set(1)
	.Timeout = 
}

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

// GetDialog returns value of Dialog field.
func ( *UpdatesChannelDifferenceTooLong) () ( DialogClass) {
	if  == nil {
		return
	}
	return .Dialog
}

// GetMessages returns value of Messages field.
func ( *UpdatesChannelDifferenceTooLong) () ( []MessageClass) {
	if  == nil {
		return
	}
	return .Messages
}

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

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

// MapMessages returns field Messages wrapped in MessageClassArray helper.
func ( *UpdatesChannelDifferenceTooLong) () ( MessageClassArray) {
	return MessageClassArray(.Messages)
}

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

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

// UpdatesChannelDifference represents TL type `updates.channelDifference#2064674e`.
// The new updates
//
// See https://core.telegram.org/constructor/updates.channelDifference for reference.
type UpdatesChannelDifference struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether there are more updates to be fetched using getDifference, starting from the
	// provided pts
	Final bool
	// The PTSĀ¹ from which to start getting updates the next time
	//
	// Links:
	//  1) https://core.telegram.org/api/updates
	Pts int
	// Clients are supposed to refetch the channel difference after timeout seconds have
	// elapsed
	//
	// Use SetTimeout and GetTimeout helpers.
	Timeout int
	// New messages
	NewMessages []MessageClass
	// Other updates
	OtherUpdates []UpdateClass
	// Chats
	Chats []ChatClass
	// Users
	Users []UserClass
}

// UpdatesChannelDifferenceTypeID is TL type id of UpdatesChannelDifference.
const UpdatesChannelDifferenceTypeID = 0x2064674e

// construct implements constructor of UpdatesChannelDifferenceClass.
func ( UpdatesChannelDifference) () UpdatesChannelDifferenceClass { return & }

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

	_ UpdatesChannelDifferenceClass = &UpdatesChannelDifference{}
)

func ( *UpdatesChannelDifference) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Final == false) {
		return false
	}
	if !(.Pts == 0) {
		return false
	}
	if !(.Timeout == 0) {
		return false
	}
	if !(.NewMessages == nil) {
		return false
	}
	if !(.OtherUpdates == nil) {
		return false
	}
	if !(.Chats == nil) {
		return false
	}
	if !(.Users == nil) {
		return false
	}

	return true
}

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

// FillFrom fills UpdatesChannelDifference from given interface.
func ( *UpdatesChannelDifference) ( interface {
	() ( bool)
	() ( int)
	() ( int,  bool)
	() ( []MessageClass)
	() ( []UpdateClass)
	() ( []ChatClass)
	() ( []UserClass)
}) {
	.Final = .()
	.Pts = .()
	if ,  := .();  {
		.Timeout = 
	}

	.NewMessages = .()
	.OtherUpdates = .()
	.Chats = .()
	.Users = .()
}

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

// TypeName returns name of type in TL schema.
func (*UpdatesChannelDifference) () string {
	return "updates.channelDifference"
}

// TypeInfo returns info about TL type.
func ( *UpdatesChannelDifference) () tdp.Type {
	 := tdp.Type{
		Name: "updates.channelDifference",
		ID:   UpdatesChannelDifferenceTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Final",
			SchemaName: "final",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Pts",
			SchemaName: "pts",
		},
		{
			Name:       "Timeout",
			SchemaName: "timeout",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "NewMessages",
			SchemaName: "new_messages",
		},
		{
			Name:       "OtherUpdates",
			SchemaName: "other_updates",
		},
		{
			Name:       "Chats",
			SchemaName: "chats",
		},
		{
			Name:       "Users",
			SchemaName: "users",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *UpdatesChannelDifference) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode updates.channelDifference#2064674e as nil")
	}
	.PutID(UpdatesChannelDifferenceTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UpdatesChannelDifference) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode updates.channelDifference#2064674e as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field flags: %w", )
	}
	.PutInt(.Pts)
	if .Flags.Has(1) {
		.PutInt(.Timeout)
	}
	.PutVectorHeader(len(.NewMessages))
	for ,  := range .NewMessages {
		if  == nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field new_messages element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field new_messages element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.OtherUpdates))
	for ,  := range .OtherUpdates {
		if  == nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field other_updates element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field other_updates element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Chats))
	for ,  := range .Chats {
		if  == nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field chats element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field chats element with index %d: %w", , )
		}
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode updates.channelDifference#2064674e: field users element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *UpdatesChannelDifference) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode updates.channelDifference#2064674e to nil")
	}
	if  := .ConsumeID(UpdatesChannelDifferenceTypeID);  != nil {
		return fmt.Errorf("unable to decode updates.channelDifference#2064674e: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *UpdatesChannelDifference) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode updates.channelDifference#2064674e to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field flags: %w", )
		}
	}
	.Final = .Flags.Has(0)
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field pts: %w", )
		}
		.Pts = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field timeout: %w", )
		}
		.Timeout = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field new_messages: %w", )
		}

		if  > 0 {
			.NewMessages = make([]MessageClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessage()
			if  != nil {
				return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field new_messages: %w", )
			}
			.NewMessages = append(.NewMessages, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field other_updates: %w", )
		}

		if  > 0 {
			.OtherUpdates = make([]UpdateClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUpdate()
			if  != nil {
				return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field other_updates: %w", )
			}
			.OtherUpdates = append(.OtherUpdates, )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field chats: %w", )
		}

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

		if  > 0 {
			.Users = make([]UserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeUser()
			if  != nil {
				return fmt.Errorf("unable to decode updates.channelDifference#2064674e: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	return nil
}

// SetFinal sets value of Final conditional field.
func ( *UpdatesChannelDifference) ( bool) {
	if  {
		.Flags.Set(0)
		.Final = true
	} else {
		.Flags.Unset(0)
		.Final = false
	}
}

// GetFinal returns value of Final conditional field.
func ( *UpdatesChannelDifference) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// GetPts returns value of Pts field.
func ( *UpdatesChannelDifference) () ( int) {
	if  == nil {
		return
	}
	return .Pts
}

// SetTimeout sets value of Timeout conditional field.
func ( *UpdatesChannelDifference) ( int) {
	.Flags.Set(1)
	.Timeout = 
}

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

// GetNewMessages returns value of NewMessages field.
func ( *UpdatesChannelDifference) () ( []MessageClass) {
	if  == nil {
		return
	}
	return .NewMessages
}

// GetOtherUpdates returns value of OtherUpdates field.
func ( *UpdatesChannelDifference) () ( []UpdateClass) {
	if  == nil {
		return
	}
	return .OtherUpdates
}

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

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

// MapNewMessages returns field NewMessages wrapped in MessageClassArray helper.
func ( *UpdatesChannelDifference) () ( MessageClassArray) {
	return MessageClassArray(.NewMessages)
}

// MapOtherUpdates returns field OtherUpdates wrapped in UpdateClassArray helper.
func ( *UpdatesChannelDifference) () ( UpdateClassArray) {
	return UpdateClassArray(.OtherUpdates)
}

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

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

// UpdatesChannelDifferenceClassName is schema name of UpdatesChannelDifferenceClass.
const UpdatesChannelDifferenceClassName = "updates.ChannelDifference"

// UpdatesChannelDifferenceClass represents updates.ChannelDifference generic type.
//
// See https://core.telegram.org/type/updates.ChannelDifference for reference.
//
// Example:
//
//	g, err := tg.DecodeUpdatesChannelDifference(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.UpdatesChannelDifferenceEmpty: // updates.channelDifferenceEmpty#3e11affb
//	case *tg.UpdatesChannelDifferenceTooLong: // updates.channelDifferenceTooLong#a4bcc6fe
//	case *tg.UpdatesChannelDifference: // updates.channelDifference#2064674e
//	default: panic(v)
//	}
type UpdatesChannelDifferenceClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() UpdatesChannelDifferenceClass

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

	// Whether there are more updates that must be fetched (always false)
	GetFinal() (value bool)

	// Clients are supposed to refetch the channel difference after timeout seconds have
	// elapsed
	GetTimeout() (value int, ok bool)

	// AsNotEmpty tries to map UpdatesChannelDifferenceClass to NotEmptyUpdatesChannelDifference.
	AsNotEmpty() (NotEmptyUpdatesChannelDifference, bool)
}

// NotEmptyUpdatesChannelDifference represents NotEmpty subset of UpdatesChannelDifferenceClass.
type NotEmptyUpdatesChannelDifference interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() UpdatesChannelDifferenceClass

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

	// Whether there are more updates that must be fetched (always false)
	GetFinal() (value bool)

	// Clients are supposed to refetch the channel difference after timeout seconds have
	// elapsed
	GetTimeout() (value int, ok bool)

	// Chats from messages
	GetChats() (value []ChatClass)

	// Users from messages
	GetUsers() (value []UserClass)
}

// AsNotEmpty tries to map UpdatesChannelDifferenceEmpty to NotEmptyUpdatesChannelDifference.
func ( *UpdatesChannelDifferenceEmpty) () (NotEmptyUpdatesChannelDifference, bool) {
	,  := (UpdatesChannelDifferenceClass()).(NotEmptyUpdatesChannelDifference)
	return , 
}

// AsNotEmpty tries to map UpdatesChannelDifferenceTooLong to NotEmptyUpdatesChannelDifference.
func ( *UpdatesChannelDifferenceTooLong) () (NotEmptyUpdatesChannelDifference, bool) {
	,  := (UpdatesChannelDifferenceClass()).(NotEmptyUpdatesChannelDifference)
	return , 
}

// AsNotEmpty tries to map UpdatesChannelDifference to NotEmptyUpdatesChannelDifference.
func ( *UpdatesChannelDifference) () (NotEmptyUpdatesChannelDifference, bool) {
	,  := (UpdatesChannelDifferenceClass()).(NotEmptyUpdatesChannelDifference)
	return , 
}

// DecodeUpdatesChannelDifference implements binary de-serialization for UpdatesChannelDifferenceClass.
func ( *bin.Buffer) (UpdatesChannelDifferenceClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case UpdatesChannelDifferenceEmptyTypeID:
		// Decoding updates.channelDifferenceEmpty#3e11affb.
		 := UpdatesChannelDifferenceEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UpdatesChannelDifferenceClass: %w", )
		}
		return &, nil
	case UpdatesChannelDifferenceTooLongTypeID:
		// Decoding updates.channelDifferenceTooLong#a4bcc6fe.
		 := UpdatesChannelDifferenceTooLong{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UpdatesChannelDifferenceClass: %w", )
		}
		return &, nil
	case UpdatesChannelDifferenceTypeID:
		// Decoding updates.channelDifference#2064674e.
		 := UpdatesChannelDifference{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UpdatesChannelDifferenceClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode UpdatesChannelDifferenceClass: %w", bin.NewUnexpectedID())
	}
}

// UpdatesChannelDifference boxes the UpdatesChannelDifferenceClass providing a helper.
type UpdatesChannelDifferenceBox struct {
	ChannelDifference UpdatesChannelDifferenceClass
}

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

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