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

// MessagesUpdatePinnedMessageRequest represents TL type `messages.updatePinnedMessage#d2aaf7ec`.
// Pin a message
//
// See https://core.telegram.org/method/messages.updatePinnedMessage for reference.
type MessagesUpdatePinnedMessageRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Pin the message silently, without triggering a notification
	Silent bool
	// Whether the message should unpinned or pinned
	Unpin bool
	// Whether the message should only be pinned on the local side of a one-to-one chat
	PmOneside bool
	// The peer where to pin the message
	Peer InputPeerClass
	// The message to pin or unpin
	ID int
}

// MessagesUpdatePinnedMessageRequestTypeID is TL type id of MessagesUpdatePinnedMessageRequest.
const MessagesUpdatePinnedMessageRequestTypeID = 0xd2aaf7ec

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

func ( *MessagesUpdatePinnedMessageRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Silent == false) {
		return false
	}
	if !(.Unpin == false) {
		return false
	}
	if !(.PmOneside == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.ID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesUpdatePinnedMessageRequest from given interface.
func ( *MessagesUpdatePinnedMessageRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( bool)
	() ( InputPeerClass)
	() ( int)
}) {
	.Silent = .()
	.Unpin = .()
	.PmOneside = .()
	.Peer = .()
	.ID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesUpdatePinnedMessageRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.updatePinnedMessage",
		ID:   MessagesUpdatePinnedMessageRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Silent",
			SchemaName: "silent",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Unpin",
			SchemaName: "unpin",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "PmOneside",
			SchemaName: "pm_oneside",
			Null:       !.Flags.Has(2),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "ID",
			SchemaName: "id",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesUpdatePinnedMessageRequest) () {
	if !(.Silent == false) {
		.Flags.Set(0)
	}
	if !(.Unpin == false) {
		.Flags.Set(1)
	}
	if !(.PmOneside == false) {
		.Flags.Set(2)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesUpdatePinnedMessageRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.updatePinnedMessage#d2aaf7ec as nil")
	}
	.PutID(MessagesUpdatePinnedMessageRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesUpdatePinnedMessageRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.updatePinnedMessage#d2aaf7ec as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.updatePinnedMessage#d2aaf7ec: field flags: %w", )
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode messages.updatePinnedMessage#d2aaf7ec: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.updatePinnedMessage#d2aaf7ec: field peer: %w", )
	}
	.PutInt(.ID)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesUpdatePinnedMessageRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.updatePinnedMessage#d2aaf7ec to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.updatePinnedMessage#d2aaf7ec: field flags: %w", )
		}
	}
	.Silent = .Flags.Has(0)
	.Unpin = .Flags.Has(1)
	.PmOneside = .Flags.Has(2)
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.updatePinnedMessage#d2aaf7ec: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode messages.updatePinnedMessage#d2aaf7ec: field id: %w", )
		}
		.ID = 
	}
	return nil
}

// SetSilent sets value of Silent conditional field.
func ( *MessagesUpdatePinnedMessageRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Silent = true
	} else {
		.Flags.Unset(0)
		.Silent = false
	}
}

// GetSilent returns value of Silent conditional field.
func ( *MessagesUpdatePinnedMessageRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetUnpin sets value of Unpin conditional field.
func ( *MessagesUpdatePinnedMessageRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.Unpin = true
	} else {
		.Flags.Unset(1)
		.Unpin = false
	}
}

// GetUnpin returns value of Unpin conditional field.
func ( *MessagesUpdatePinnedMessageRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetPmOneside sets value of PmOneside conditional field.
func ( *MessagesUpdatePinnedMessageRequest) ( bool) {
	if  {
		.Flags.Set(2)
		.PmOneside = true
	} else {
		.Flags.Unset(2)
		.PmOneside = false
	}
}

// GetPmOneside returns value of PmOneside conditional field.
func ( *MessagesUpdatePinnedMessageRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(2)
}

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

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

// MessagesUpdatePinnedMessage invokes method messages.updatePinnedMessage#d2aaf7ec returning error if any.
// Pin a message
//
// Possible errors:
//
//	400 BOT_ONESIDE_NOT_AVAIL: Bots can't pin messages in PM just for themselves.
//	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_NOT_MODIFIED: No changes were made to chat information because the new information you passed is identical to the current information.
//	403 CHAT_WRITE_FORBIDDEN: You can't write in this chat.
//	400 MESSAGE_ID_INVALID: The provided message id is invalid.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 PIN_RESTRICTED: You can't pin messages.
//	400 USER_BANNED_IN_CHANNEL: You're banned from sending messages in supergroups/channels.
//
// See https://core.telegram.org/method/messages.updatePinnedMessage for reference.
// Can be used by bots.
func ( *Client) ( context.Context,  *MessagesUpdatePinnedMessageRequest) (UpdatesClass, error) {
	var  UpdatesBox

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