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

// MessagesCreateChatRequest represents TL type `messages.createChat#34a818`.
// Creates a new chat.
// May also return 0-N updates of type updateGroupInvitePrivacyForbidden¹: it indicates
// we couldn't add a user to a chat because of their privacy settings; if required, an
// invite link² can be shared with the user, instead.
//
// Links:
//  1. https://core.telegram.org/constructor/updateGroupInvitePrivacyForbidden
//  2. https://core.telegram.org/api/invites
//
// See https://core.telegram.org/method/messages.createChat for reference.
type MessagesCreateChatRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// List of user IDs to be invited
	Users []InputUserClass
	// Chat name
	Title string
	// Time-to-live of all messages that will be sent in the chat: once message.date+message
	// ttl_period === time(), the message will be deleted on the server, and must be deleted
	// locally as well. You can use messages.setDefaultHistoryTTL¹ to edit this value later.
	//
	// Links:
	//  1) https://core.telegram.org/method/messages.setDefaultHistoryTTL
	//
	// Use SetTTLPeriod and GetTTLPeriod helpers.
	TTLPeriod int
}

// MessagesCreateChatRequestTypeID is TL type id of MessagesCreateChatRequest.
const MessagesCreateChatRequestTypeID = 0x34a818

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

func ( *MessagesCreateChatRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Users == nil) {
		return false
	}
	if !(.Title == "") {
		return false
	}
	if !(.TTLPeriod == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesCreateChatRequest from given interface.
func ( *MessagesCreateChatRequest) ( interface {
	() ( []InputUserClass)
	() ( string)
	() ( int,  bool)
}) {
	.Users = .()
	.Title = .()
	if ,  := .();  {
		.TTLPeriod = 
	}

}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesCreateChatRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.createChat",
		ID:   MessagesCreateChatRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Users",
			SchemaName: "users",
		},
		{
			Name:       "Title",
			SchemaName: "title",
		},
		{
			Name:       "TTLPeriod",
			SchemaName: "ttl_period",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesCreateChatRequest) () {
	if !(.TTLPeriod == 0) {
		.Flags.Set(0)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesCreateChatRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.createChat#34a818 as nil")
	}
	.PutID(MessagesCreateChatRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesCreateChatRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.createChat#34a818 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.createChat#34a818: field flags: %w", )
	}
	.PutVectorHeader(len(.Users))
	for ,  := range .Users {
		if  == nil {
			return fmt.Errorf("unable to encode messages.createChat#34a818: field users element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode messages.createChat#34a818: field users element with index %d: %w", , )
		}
	}
	.PutString(.Title)
	if .Flags.Has(0) {
		.PutInt(.TTLPeriod)
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesCreateChatRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.createChat#34a818 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.createChat#34a818: field flags: %w", )
		}
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.createChat#34a818: field users: %w", )
		}

		if  > 0 {
			.Users = make([]InputUserClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeInputUser()
			if  != nil {
				return fmt.Errorf("unable to decode messages.createChat#34a818: field users: %w", )
			}
			.Users = append(.Users, )
		}
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.createChat#34a818: field title: %w", )
		}
		.Title = 
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.createChat#34a818: field ttl_period: %w", )
		}
		.TTLPeriod = 
	}
	return nil
}

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

// GetTitle returns value of Title field.
func ( *MessagesCreateChatRequest) () ( string) {
	if  == nil {
		return
	}
	return .Title
}

// SetTTLPeriod sets value of TTLPeriod conditional field.
func ( *MessagesCreateChatRequest) ( int) {
	.Flags.Set(0)
	.TTLPeriod = 
}

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

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

// MessagesCreateChat invokes method messages.createChat#34a818 returning error if any.
// Creates a new chat.
// May also return 0-N updates of type updateGroupInvitePrivacyForbidden¹: it indicates
// we couldn't add a user to a chat because of their privacy settings; if required, an
// invite link² can be shared with the user, instead.
//
// Links:
//  1. https://core.telegram.org/constructor/updateGroupInvitePrivacyForbidden
//  2. https://core.telegram.org/api/invites
//
// Possible errors:
//
//	500 CHAT_ID_GENERATE_FAILED: Failure while generating the chat ID.
//	400 CHAT_INVALID: Invalid chat.
//	400 CHAT_TITLE_EMPTY: No chat title provided.
//	400 INPUT_USER_DEACTIVATED: The specified user was deleted.
//	400 TTL_PERIOD_INVALID: The specified TTL period is invalid.
//	400 USERS_TOO_FEW: Not enough users (to create a chat, for example).
//	406 USER_RESTRICTED: You're spamreported, you can't create channels or chats.
//
// See https://core.telegram.org/method/messages.createChat for reference.
func ( *Client) ( context.Context,  *MessagesCreateChatRequest) (UpdatesClass, error) {
	var  UpdatesBox

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