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

// MessagesSaveDraftRequest represents TL type `messages.saveDraft#7ff3b806`.
// Save a message draft¹ associated to a chat.
//
// Links:
//  1. https://core.telegram.org/api/drafts
//
// See https://core.telegram.org/method/messages.saveDraft for reference.
type MessagesSaveDraftRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Disable generation of the webpage preview
	NoWebpage bool
	// If set, any eventual webpage preview will be shown on top of the message instead of at
	// the bottom.
	InvertMedia bool
	// If set, indicates that the message should be sent in reply to the specified message or
	// story.
	//
	// Use SetReplyTo and GetReplyTo helpers.
	ReplyTo InputReplyToClass
	// Destination of the message that should be sent
	Peer InputPeerClass
	// The draft
	Message string
	// Message entities¹ for styled text
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetEntities and GetEntities helpers.
	Entities []MessageEntityClass
	// Attached media
	//
	// Use SetMedia and GetMedia helpers.
	Media InputMediaClass
}

// MessagesSaveDraftRequestTypeID is TL type id of MessagesSaveDraftRequest.
const MessagesSaveDraftRequestTypeID = 0x7ff3b806

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

func ( *MessagesSaveDraftRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.NoWebpage == false) {
		return false
	}
	if !(.InvertMedia == false) {
		return false
	}
	if !(.ReplyTo == nil) {
		return false
	}
	if !(.Peer == nil) {
		return false
	}
	if !(.Message == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}
	if !(.Media == nil) {
		return false
	}

	return true
}

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

// FillFrom fills MessagesSaveDraftRequest from given interface.
func ( *MessagesSaveDraftRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( InputReplyToClass,  bool)
	() ( InputPeerClass)
	() ( string)
	() ( []MessageEntityClass,  bool)
	() ( InputMediaClass,  bool)
}) {
	.NoWebpage = .()
	.InvertMedia = .()
	if ,  := .();  {
		.ReplyTo = 
	}

	.Peer = .()
	.Message = .()
	if ,  := .();  {
		.Entities = 
	}

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

}

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

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

// TypeInfo returns info about TL type.
func ( *MessagesSaveDraftRequest) () tdp.Type {
	 := tdp.Type{
		Name: "messages.saveDraft",
		ID:   MessagesSaveDraftRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "NoWebpage",
			SchemaName: "no_webpage",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "InvertMedia",
			SchemaName: "invert_media",
			Null:       !.Flags.Has(6),
		},
		{
			Name:       "ReplyTo",
			SchemaName: "reply_to",
			Null:       !.Flags.Has(4),
		},
		{
			Name:       "Peer",
			SchemaName: "peer",
		},
		{
			Name:       "Message",
			SchemaName: "message",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Media",
			SchemaName: "media",
			Null:       !.Flags.Has(5),
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *MessagesSaveDraftRequest) () {
	if !(.NoWebpage == false) {
		.Flags.Set(1)
	}
	if !(.InvertMedia == false) {
		.Flags.Set(6)
	}
	if !(.ReplyTo == nil) {
		.Flags.Set(4)
	}
	if !(.Entities == nil) {
		.Flags.Set(3)
	}
	if !(.Media == nil) {
		.Flags.Set(5)
	}
}

// Encode implements bin.Encoder.
func ( *MessagesSaveDraftRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.saveDraft#7ff3b806 as nil")
	}
	.PutID(MessagesSaveDraftRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *MessagesSaveDraftRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode messages.saveDraft#7ff3b806 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field flags: %w", )
	}
	if .Flags.Has(4) {
		if .ReplyTo == nil {
			return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field reply_to is nil")
		}
		if  := .ReplyTo.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field reply_to: %w", )
		}
	}
	if .Peer == nil {
		return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field peer is nil")
	}
	if  := .Peer.Encode();  != nil {
		return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field peer: %w", )
	}
	.PutString(.Message)
	if .Flags.Has(3) {
		.PutVectorHeader(len(.Entities))
		for ,  := range .Entities {
			if  == nil {
				return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field entities element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field entities element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(5) {
		if .Media == nil {
			return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field media is nil")
		}
		if  := .Media.Encode();  != nil {
			return fmt.Errorf("unable to encode messages.saveDraft#7ff3b806: field media: %w", )
		}
	}
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *MessagesSaveDraftRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode messages.saveDraft#7ff3b806 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode messages.saveDraft#7ff3b806: field flags: %w", )
		}
	}
	.NoWebpage = .Flags.Has(1)
	.InvertMedia = .Flags.Has(6)
	if .Flags.Has(4) {
		,  := DecodeInputReplyTo()
		if  != nil {
			return fmt.Errorf("unable to decode messages.saveDraft#7ff3b806: field reply_to: %w", )
		}
		.ReplyTo = 
	}
	{
		,  := DecodeInputPeer()
		if  != nil {
			return fmt.Errorf("unable to decode messages.saveDraft#7ff3b806: field peer: %w", )
		}
		.Peer = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode messages.saveDraft#7ff3b806: field message: %w", )
		}
		.Message = 
	}
	if .Flags.Has(3) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode messages.saveDraft#7ff3b806: field entities: %w", )
		}

		if  > 0 {
			.Entities = make([]MessageEntityClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeMessageEntity()
			if  != nil {
				return fmt.Errorf("unable to decode messages.saveDraft#7ff3b806: field entities: %w", )
			}
			.Entities = append(.Entities, )
		}
	}
	if .Flags.Has(5) {
		,  := DecodeInputMedia()
		if  != nil {
			return fmt.Errorf("unable to decode messages.saveDraft#7ff3b806: field media: %w", )
		}
		.Media = 
	}
	return nil
}

// SetNoWebpage sets value of NoWebpage conditional field.
func ( *MessagesSaveDraftRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.NoWebpage = true
	} else {
		.Flags.Unset(1)
		.NoWebpage = false
	}
}

// GetNoWebpage returns value of NoWebpage conditional field.
func ( *MessagesSaveDraftRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// SetInvertMedia sets value of InvertMedia conditional field.
func ( *MessagesSaveDraftRequest) ( bool) {
	if  {
		.Flags.Set(6)
		.InvertMedia = true
	} else {
		.Flags.Unset(6)
		.InvertMedia = false
	}
}

// GetInvertMedia returns value of InvertMedia conditional field.
func ( *MessagesSaveDraftRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(6)
}

// SetReplyTo sets value of ReplyTo conditional field.
func ( *MessagesSaveDraftRequest) ( InputReplyToClass) {
	.Flags.Set(4)
	.ReplyTo = 
}

// GetReplyTo returns value of ReplyTo conditional field and
// boolean which is true if field was set.
func ( *MessagesSaveDraftRequest) () ( InputReplyToClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(4) {
		return , false
	}
	return .ReplyTo, true
}

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

// GetMessage returns value of Message field.
func ( *MessagesSaveDraftRequest) () ( string) {
	if  == nil {
		return
	}
	return .Message
}

// SetEntities sets value of Entities conditional field.
func ( *MessagesSaveDraftRequest) ( []MessageEntityClass) {
	.Flags.Set(3)
	.Entities = 
}

// GetEntities returns value of Entities conditional field and
// boolean which is true if field was set.
func ( *MessagesSaveDraftRequest) () ( []MessageEntityClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(3) {
		return , false
	}
	return .Entities, true
}

// SetMedia sets value of Media conditional field.
func ( *MessagesSaveDraftRequest) ( InputMediaClass) {
	.Flags.Set(5)
	.Media = 
}

// GetMedia returns value of Media conditional field and
// boolean which is true if field was set.
func ( *MessagesSaveDraftRequest) () ( InputMediaClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(5) {
		return , false
	}
	return .Media, true
}

// MapEntities returns field Entities wrapped in MessageEntityClassArray helper.
func ( *MessagesSaveDraftRequest) () ( MessageEntityClassArray,  bool) {
	if !.Flags.Has(3) {
		return , false
	}
	return MessageEntityClassArray(.Entities), true
}

// MessagesSaveDraft invokes method messages.saveDraft#7ff3b806 returning error if any.
// Save a message draft¹ associated to a chat.
//
// Links:
//  1. https://core.telegram.org/api/drafts
//
// Possible errors:
//
//	400 ENTITY_BOUNDS_INVALID: A specified entity offset or length is invalid, see here » for info on how to properly compute the entity offset/length.
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/messages.saveDraft for reference.
func ( *Client) ( context.Context,  *MessagesSaveDraftRequest) (bool, error) {
	var  BoolBox

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