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

// MessagesToggleDialogPinRequest represents TL type `messages.toggleDialogPin#a731e257`.
// Pin/unpin a dialog
//
// See https://core.telegram.org/method/messages.toggleDialogPin for reference.
type MessagesToggleDialogPinRequest struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether to pin or unpin the dialog
	Pinned bool
	// The dialog to pin
	Peer InputDialogPeerClass
}

// MessagesToggleDialogPinRequestTypeID is TL type id of MessagesToggleDialogPinRequest.
const MessagesToggleDialogPinRequestTypeID = 0xa731e257

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

func ( *MessagesToggleDialogPinRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Pinned == false) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesToggleDialogPinRequest from given interface.
func ( *MessagesToggleDialogPinRequest) ( interface {
	() ( bool)
	() ( InputDialogPeerClass)
}) {
	.Pinned = .()
	.Peer = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesToggleDialogPinRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.toggleDialogPin",
		ID:   MessagesToggleDialogPinRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Pinned",
			SchemaName: "pinned",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *MessagesToggleDialogPinRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.toggleDialogPin#a731e257 as nil")
	}
	.PutID(MessagesToggleDialogPinRequestTypeID)
	return .EncodeBare()
}

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

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesToggleDialogPinRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.toggleDialogPin#a731e257 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.toggleDialogPin#a731e257: field flags: %w", )
		}
	}
	.Pinned = .Flags.Has(0)
	{
		,  := DecodeInputDialogPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.toggleDialogPin#a731e257: field peer: %w", )
		}
		.Peer = 
	}
	return nil
}

// SetPinned sets value of Pinned conditional field.
func ( *MessagesToggleDialogPinRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Pinned = true
	} else {
		.Flags.Unset(0)
		.Pinned = false
	}
}

// GetPinned returns value of Pinned conditional field.
func ( *MessagesToggleDialogPinRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

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

// MessagesToggleDialogPin invokes method messages.toggleDialogPin#a731e257 returning error if any.
// Pin/unpin a dialog
//
// Possible errors:
//
//	400 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
//	400 PEER_HISTORY_EMPTY: You can't pin an empty chat with a user.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//	400 PINNED_DIALOGS_TOO_MUCH: Too many pinned dialogs.
//
// See https://core.telegram.org/method/messages.toggleDialogPin for reference.
func ( *Client) ( context.Context,  *MessagesToggleDialogPinRequest) (bool, error) {
	var  BoolBox

	if  := .rpc.Invoke(, , &);  != nil {
		return false, 
	}
	,  := .Bool.(*BoolTrue)
	return , nil
}