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

// ChatInviteExported represents TL type `chatInviteExported#ab4a819`.
// Exported chat invite
//
// See https://core.telegram.org/constructor/chatInviteExported for reference.
type ChatInviteExported struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether this chat invite was revoked
	Revoked bool
	// Whether this chat invite has no expiration
	Permanent bool
	// Whether users importing this invite link will have to be approved to join the channel
	// or group
	RequestNeeded bool
	// Chat invitation link
	Link string
	// ID of the admin that created this chat invite
	AdminID int64
	// When was this chat invite created
	Date int
	// When was this chat invite last modified
	//
	// Use SetStartDate and GetStartDate helpers.
	StartDate int
	// When does this chat invite expire
	//
	// Use SetExpireDate and GetExpireDate helpers.
	ExpireDate int
	// Maximum number of users that can join using this link
	//
	// Use SetUsageLimit and GetUsageLimit helpers.
	UsageLimit int
	// How many users joined using this link
	//
	// Use SetUsage and GetUsage helpers.
	Usage int
	// Number of users that have already used this link to join
	//
	// Use SetRequested and GetRequested helpers.
	Requested int
	// Custom description for the invite link, visible only to admins
	//
	// Use SetTitle and GetTitle helpers.
	Title string
}

// ChatInviteExportedTypeID is TL type id of ChatInviteExported.
const ChatInviteExportedTypeID = 0xab4a819

// construct implements constructor of ExportedChatInviteClass.
func ( ChatInviteExported) () ExportedChatInviteClass { return & }

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

	_ ExportedChatInviteClass = &ChatInviteExported{}
)

func ( *ChatInviteExported) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Revoked == false) {
		return false
	}
	if !(.Permanent == false) {
		return false
	}
	if !(.RequestNeeded == false) {
		return false
	}
	if !(.Link == "") {
		return false
	}
	if !(.AdminID == 0) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.StartDate == 0) {
		return false
	}
	if !(.ExpireDate == 0) {
		return false
	}
	if !(.UsageLimit == 0) {
		return false
	}
	if !(.Usage == 0) {
		return false
	}
	if !(.Requested == 0) {
		return false
	}
	if !(.Title == "") {
		return false
	}

	return true
}

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

// FillFrom fills ChatInviteExported from given interface.
func ( *ChatInviteExported) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( string)
	() ( int64)
	() ( int)
	() ( int,  bool)
	() ( int,  bool)
	() ( int,  bool)
	() ( int,  bool)
	() ( int,  bool)
	() ( string,  bool)
}) {
	.Revoked = .()
	.Permanent = .()
	.RequestNeeded = .()
	.Link = .()
	.AdminID = .()
	.Date = .()
	if ,  := .();  {
		.StartDate = 
	}

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

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

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

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

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

}

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

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

// TypeInfo returns info about TL type.
func ( *ChatInviteExported) () tdp.Type {
	 := tdp.Type{
		Name: "chatInviteExported",
		ID:   ChatInviteExportedTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Revoked",
			SchemaName: "revoked",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Permanent",
			SchemaName: "permanent",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "RequestNeeded",
			SchemaName: "request_needed",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "Link",
			SchemaName: "link",
		},
		{
			Name:       "AdminID",
			SchemaName: "admin_id",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "StartDate",
			SchemaName: "start_date",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "ExpireDate",
			SchemaName: "expire_date",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "UsageLimit",
			SchemaName: "usage_limit",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Usage",
			SchemaName: "usage",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Requested",
			SchemaName: "requested",
			Null:       !.Flags.Has(7),
		},
		{
			Name:       "Title",
			SchemaName: "title",
			Null:       !.Flags.Has(8),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *ChatInviteExported) () {
	if !(.Revoked == false) {
		.Flags.Set(0)
	}
	if !(.Permanent == false) {
		.Flags.Set(5)
	}
	if !(.RequestNeeded == false) {
		.Flags.Set(6)
	}
	if !(.StartDate == 0) {
		.Flags.Set(4)
	}
	if !(.ExpireDate == 0) {
		.Flags.Set(1)
	}
	if !(.UsageLimit == 0) {
		.Flags.Set(2)
	}
	if !(.Usage == 0) {
		.Flags.Set(3)
	}
	if !(.Requested == 0) {
		.Flags.Set(7)
	}
	if !(.Title == "") {
		.Flags.Set(8)
	}
}

// Encode implements bin.Encoder.
func ( *ChatInviteExported) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatInviteExported#ab4a819 as nil")
	}
	.PutID(ChatInviteExportedTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatInviteExported) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatInviteExported#ab4a819 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode chatInviteExported#ab4a819: field flags: %w", )
	}
	.PutString(.Link)
	.PutLong(.AdminID)
	.PutInt(.Date)
	if .Flags.Has(4) {
		.PutInt(.StartDate)
	}
	if .Flags.Has(1) {
		.PutInt(.ExpireDate)
	}
	if .Flags.Has(2) {
		.PutInt(.UsageLimit)
	}
	if .Flags.Has(3) {
		.PutInt(.Usage)
	}
	if .Flags.Has(7) {
		.PutInt(.Requested)
	}
	if .Flags.Has(8) {
		.PutString(.Title)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ChatInviteExported) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatInviteExported#ab4a819 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field flags: %w", )
		}
	}
	.Revoked = .Flags.Has(0)
	.Permanent = .Flags.Has(5)
	.RequestNeeded = .Flags.Has(6)
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field link: %w", )
		}
		.Link = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field admin_id: %w", )
		}
		.AdminID = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field date: %w", )
		}
		.Date = 
	}
	if .Flags.Has(4) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field start_date: %w", )
		}
		.StartDate = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field expire_date: %w", )
		}
		.ExpireDate = 
	}
	if .Flags.Has(2) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field usage_limit: %w", )
		}
		.UsageLimit = 
	}
	if .Flags.Has(3) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field usage: %w", )
		}
		.Usage = 
	}
	if .Flags.Has(7) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field requested: %w", )
		}
		.Requested = 
	}
	if .Flags.Has(8) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode chatInviteExported#ab4a819: field title: %w", )
		}
		.Title = 
	}
	return nil
}

// SetRevoked sets value of Revoked conditional field.
func ( *ChatInviteExported) ( bool) {
	if  {
		.Flags.Set(0)
		.Revoked = true
	} else {
		.Flags.Unset(0)
		.Revoked = false
	}
}

// GetRevoked returns value of Revoked conditional field.
func ( *ChatInviteExported) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetPermanent sets value of Permanent conditional field.
func ( *ChatInviteExported) ( bool) {
	if  {
		.Flags.Set(5)
		.Permanent = true
	} else {
		.Flags.Unset(5)
		.Permanent = false
	}
}

// GetPermanent returns value of Permanent conditional field.
func ( *ChatInviteExported) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(5)
}

// SetRequestNeeded sets value of RequestNeeded conditional field.
func ( *ChatInviteExported) ( bool) {
	if  {
		.Flags.Set(6)
		.RequestNeeded = true
	} else {
		.Flags.Unset(6)
		.RequestNeeded = false
	}
}

// GetRequestNeeded returns value of RequestNeeded conditional field.
func ( *ChatInviteExported) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(6)
}

// GetLink returns value of Link field.
func ( *ChatInviteExported) () ( string) {
	if  == nil {
		return
	}
	return .Link
}

// GetAdminID returns value of AdminID field.
func ( *ChatInviteExported) () ( int64) {
	if  == nil {
		return
	}
	return .AdminID
}

// GetDate returns value of Date field.
func ( *ChatInviteExported) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

// SetStartDate sets value of StartDate conditional field.
func ( *ChatInviteExported) ( int) {
	.Flags.Set(4)
	.StartDate = 
}

// GetStartDate returns value of StartDate conditional field and
// boolean which is true if field was set.
func ( *ChatInviteExported) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .StartDate, true
}

// SetExpireDate sets value of ExpireDate conditional field.
func ( *ChatInviteExported) ( int) {
	.Flags.Set(1)
	.ExpireDate = 
}

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

// SetUsageLimit sets value of UsageLimit conditional field.
func ( *ChatInviteExported) ( int) {
	.Flags.Set(2)
	.UsageLimit = 
}

// GetUsageLimit returns value of UsageLimit conditional field and
// boolean which is true if field was set.
func ( *ChatInviteExported) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(2) {
		return , false
	}
	return .UsageLimit, true
}

// SetUsage sets value of Usage conditional field.
func ( *ChatInviteExported) ( int) {
	.Flags.Set(3)
	.Usage = 
}

// GetUsage returns value of Usage conditional field and
// boolean which is true if field was set.
func ( *ChatInviteExported) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Usage, true
}

// SetRequested sets value of Requested conditional field.
func ( *ChatInviteExported) ( int) {
	.Flags.Set(7)
	.Requested = 
}

// GetRequested returns value of Requested conditional field and
// boolean which is true if field was set.
func ( *ChatInviteExported) () ( int,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(7) {
		return , false
	}
	return .Requested, true
}

// SetTitle sets value of Title conditional field.
func ( *ChatInviteExported) ( string) {
	.Flags.Set(8)
	.Title = 
}

// GetTitle returns value of Title conditional field and
// boolean which is true if field was set.
func ( *ChatInviteExported) () ( string,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(8) {
		return , false
	}
	return .Title, true
}

// ChatInvitePublicJoinRequests represents TL type `chatInvitePublicJoinRequests#ed107ab7`.
// Used in updates and in the channel log to indicate when a user is requesting to join
// or has joined a discussion groupĀ¹
//
// Links:
//  1. https://core.telegram.org/api/discussion#requiring-users-to-join-the-group
//
// See https://core.telegram.org/constructor/chatInvitePublicJoinRequests for reference.
type ChatInvitePublicJoinRequests struct {
}

// ChatInvitePublicJoinRequestsTypeID is TL type id of ChatInvitePublicJoinRequests.
const ChatInvitePublicJoinRequestsTypeID = 0xed107ab7

// construct implements constructor of ExportedChatInviteClass.
func ( ChatInvitePublicJoinRequests) () ExportedChatInviteClass { return & }

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

	_ ExportedChatInviteClass = &ChatInvitePublicJoinRequests{}
)

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

	return true
}

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

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

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

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

// Encode implements bin.Encoder.
func ( *ChatInvitePublicJoinRequests) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatInvitePublicJoinRequests#ed107ab7 as nil")
	}
	.PutID(ChatInvitePublicJoinRequestsTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *ChatInvitePublicJoinRequests) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode chatInvitePublicJoinRequests#ed107ab7 as nil")
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *ChatInvitePublicJoinRequests) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode chatInvitePublicJoinRequests#ed107ab7 to nil")
	}
	return nil
}

// ExportedChatInviteClassName is schema name of ExportedChatInviteClass.
const ExportedChatInviteClassName = "ExportedChatInvite"

// ExportedChatInviteClass represents ExportedChatInvite generic type.
//
// See https://core.telegram.org/type/ExportedChatInvite for reference.
//
// Example:
//
//	g, err := tg.DecodeExportedChatInvite(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.ChatInviteExported: // chatInviteExported#ab4a819
//	case *tg.ChatInvitePublicJoinRequests: // chatInvitePublicJoinRequests#ed107ab7
//	default: panic(v)
//	}
type ExportedChatInviteClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() ExportedChatInviteClass

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

// DecodeExportedChatInvite implements binary de-serialization for ExportedChatInviteClass.
func ( *bin.Buffer) (ExportedChatInviteClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case ChatInviteExportedTypeID:
		// Decoding chatInviteExported#ab4a819.
		 := ChatInviteExported{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ExportedChatInviteClass: %w", )
		}
		return &, nil
	case ChatInvitePublicJoinRequestsTypeID:
		// Decoding chatInvitePublicJoinRequests#ed107ab7.
		 := ChatInvitePublicJoinRequests{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode ExportedChatInviteClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode ExportedChatInviteClass: %w", bin.NewUnexpectedID())
	}
}

// ExportedChatInvite boxes the ExportedChatInviteClass providing a helper.
type ExportedChatInviteBox struct {
	ExportedChatInvite ExportedChatInviteClass
}

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

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