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

// MessagesExportChatInviteRequest represents TL type `messages.exportChatInvite#a02ce5d5`.
// Export an invite link for a chat
//
// See https://core.telegram.org/method/messages.exportChatInvite for reference.
type MessagesExportChatInviteRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Legacy flag, reproducing legacy behavior of this method: if set, revokes all previous
	// links before creating a new one. Kept for bot API BC, should not be used by modern
	// clients.
	LegacyRevokePermanent bool
	// Whether admin confirmation is required before admitting each separate user into the
	// chat
	RequestNeeded bool
	// Chat
	Peer InputPeerClass
	// Expiration date
	//
	// Use SetExpireDate and GetExpireDate helpers.
	ExpireDate int
	// Maximum number of users that can join using this link
	//
	// Use SetUsageLimit and GetUsageLimit helpers.
	UsageLimit int
	// Description of the invite link, visible only to administrators
	//
	// Use SetTitle and GetTitle helpers.
	Title string
}

// MessagesExportChatInviteRequestTypeID is TL type id of MessagesExportChatInviteRequest.
const MessagesExportChatInviteRequestTypeID = 0xa02ce5d5

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

func ( *MessagesExportChatInviteRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.LegacyRevokePermanent == false) {
		return false
	}
	if !(.RequestNeeded == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.ExpireDate == 0) {
		return false
	}
	if !(.UsageLimit == 0) {
		return false
	}
	if !(.Title == "") {
		return false
	}

	return true
}

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

// FillFrom fills MessagesExportChatInviteRequest from given interface.
func ( *MessagesExportChatInviteRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( InputPeerClass)
	() ( int,  bool)
	() ( int,  bool)
	() ( string,  bool)
}) {
	.LegacyRevokePermanent = .()
	.RequestNeeded = .()
	.Peer = .()
	if ,  := .();  {
		.ExpireDate = 
	}

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

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

}

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

// TypeName returns name of type in TL schema.
func (*MessagesExportChatInviteRequest) () string {
	return "messages.exportChatInvite"
}

// TypeInfo returns info about TL type.
func ( *MessagesExportChatInviteRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.exportChatInvite",
		ID:   MessagesExportChatInviteRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "LegacyRevokePermanent",
			SchemaName: "legacy_revoke_permanent",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "RequestNeeded",
			SchemaName: "request_needed",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "ExpireDate",
			SchemaName: "expire_date",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "UsageLimit",
			SchemaName: "usage_limit",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Title",
			SchemaName: "title",
			Null:       !.Flags.Has(4),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesExportChatInviteRequest) () {
	if !(.LegacyRevokePermanent == false) {
		.Flags.Set(2)
	}
	if !(.RequestNeeded == false) {
		.Flags.Set(3)
	}
	if !(.ExpireDate == 0) {
		.Flags.Set(0)
	}
	if !(.UsageLimit == 0) {
		.Flags.Set(1)
	}
	if !(.Title == "") {
		.Flags.Set(4)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesExportChatInviteRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.exportChatInvite#a02ce5d5 as nil")
	}
	.PutID(MessagesExportChatInviteRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesExportChatInviteRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.exportChatInvite#a02ce5d5 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.exportChatInvite#a02ce5d5: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode messages.exportChatInvite#a02ce5d5: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.exportChatInvite#a02ce5d5: field peer: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.ExpireDate)
	}
	if .Flags.Has(1) {
		.PutInt(.UsageLimit)
	}
	if .Flags.Has(4) {
		.PutString(.Title)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesExportChatInviteRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.exportChatInvite#a02ce5d5 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field flags: %w", )
		}
	}
	.LegacyRevokePermanent = .Flags.Has(2)
	.RequestNeeded = .Flags.Has(3)
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field peer: %w", )
		}
		.Peer = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field expire_date: %w", )
		}
		.ExpireDate = 
	}
	if .Flags.Has(1) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field usage_limit: %w", )
		}
		.UsageLimit = 
	}
	if .Flags.Has(4) {
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.exportChatInvite#a02ce5d5: field title: %w", )
		}
		.Title = 
	}
	return nil
}

// SetLegacyRevokePermanent sets value of LegacyRevokePermanent conditional field.
func ( *MessagesExportChatInviteRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.LegacyRevokePermanent = true
	} else {
		.Flags.Unset(2)
		.LegacyRevokePermanent = false
	}
}

// GetLegacyRevokePermanent returns value of LegacyRevokePermanent conditional field.
func ( *MessagesExportChatInviteRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

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

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

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

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

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

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

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

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

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

// MessagesExportChatInvite invokes method messages.exportChatInvite#a02ce5d5 returning error if any.
// Export an invite link for a chat
//
// Possible errors:
//
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	400 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
//	400 CHAT_ADMIN_REQUIRED: You must be an admin in this chat to do this.
//	400 CHAT_ID_INVALID: The provided chat id is invalid.
//	403 CHAT_WRITE_FORBIDDEN: You can't write in this chat.
//	400 EXPIRE_DATE_INVALID: The specified expiration date is invalid.
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 USAGE_LIMIT_INVALID: The specified usage limit is invalid.
//
// See https://core.telegram.org/method/messages.exportChatInvite for reference.
// Can be used by bots.
func ( *Client) ( context.Context,  *MessagesExportChatInviteRequest) (ExportedChatInviteClass, error) {
	var  ExportedChatInviteBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .ExportedChatInvite, nil
}