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

// DraftMessageEmpty represents TL type `draftMessageEmpty#1b0c841a`.
// Empty draft
//
// See https://core.telegram.org/constructor/draftMessageEmpty for reference.
type DraftMessageEmpty struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// When was the draft last updated
	//
	// Use SetDate and GetDate helpers.
	Date int
}

// DraftMessageEmptyTypeID is TL type id of DraftMessageEmpty.
const DraftMessageEmptyTypeID = 0x1b0c841a

// construct implements constructor of DraftMessageClass.
func ( DraftMessageEmpty) () DraftMessageClass { return & }

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

	_ DraftMessageClass = &DraftMessageEmpty{}
)

func ( *DraftMessageEmpty) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Date == 0) {
		return false
	}

	return true
}

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

// FillFrom fills DraftMessageEmpty from given interface.
func ( *DraftMessageEmpty) ( interface {
	() ( int,  bool)
}) {
	if ,  := .();  {
		.Date = 
	}

}

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

// TypeName returns name of type in TL schema.
func (*DraftMessageEmpty) () string {
	return "draftMessageEmpty"
}

// TypeInfo returns info about TL type.
func ( *DraftMessageEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "draftMessageEmpty",
		ID:   DraftMessageEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Date",
			SchemaName: "date",
			Null:       !.Flags.Has(0),
		},
	}
	return 
}

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

// Encode implements bin.Encoder.
func ( *DraftMessageEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode draftMessageEmpty#1b0c841a as nil")
	}
	.PutID(DraftMessageEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *DraftMessageEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode draftMessageEmpty#1b0c841a as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode draftMessageEmpty#1b0c841a: field flags: %w", )
	}
	if .Flags.Has(0) {
		.PutInt(.Date)
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *DraftMessageEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode draftMessageEmpty#1b0c841a to nil")
	}
	if  := .ConsumeID(DraftMessageEmptyTypeID);  != nil {
		return fmt.Errorf("unable to decode draftMessageEmpty#1b0c841a: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *DraftMessageEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode draftMessageEmpty#1b0c841a to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode draftMessageEmpty#1b0c841a: field flags: %w", )
		}
	}
	if .Flags.Has(0) {
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode draftMessageEmpty#1b0c841a: field date: %w", )
		}
		.Date = 
	}
	return nil
}

// SetDate sets value of Date conditional field.
func ( *DraftMessageEmpty) ( int) {
	.Flags.Set(0)
	.Date = 
}

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

// DraftMessage represents TL type `draftMessage#3fccf7ef`.
// Represents a message draft¹.
//
// Links:
//  1. https://core.telegram.org/api/drafts
//
// See https://core.telegram.org/constructor/draftMessage for reference.
type DraftMessage struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Whether no webpage preview will be generated
	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
	// The draft
	Message string
	// Message entities¹ for styled text.
	//
	// Links:
	//  1) https://core.telegram.org/api/entities
	//
	// Use SetEntities and GetEntities helpers.
	Entities []MessageEntityClass
	// Media.
	//
	// Use SetMedia and GetMedia helpers.
	Media InputMediaClass
	// Date of last update of the draft.
	Date int
}

// DraftMessageTypeID is TL type id of DraftMessage.
const DraftMessageTypeID = 0x3fccf7ef

// construct implements constructor of DraftMessageClass.
func ( DraftMessage) () DraftMessageClass { return & }

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

	_ DraftMessageClass = &DraftMessage{}
)

func ( *DraftMessage) () 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 !(.Message == "") {
		return false
	}
	if !(.Entities == nil) {
		return false
	}
	if !(.Media == nil) {
		return false
	}
	if !(.Date == 0) {
		return false
	}

	return true
}

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

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

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

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

	.Date = .()
}

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

// TypeName returns name of type in TL schema.
func (*DraftMessage) () string {
	return "draftMessage"
}

// TypeInfo returns info about TL type.
func ( *DraftMessage) () tdp.Type {
	 := tdp.Type{
		Name: "draftMessage",
		ID:   DraftMessageTypeID,
	}
	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:       "Message",
			SchemaName: "message",
		},
		{
			Name:       "Entities",
			SchemaName: "entities",
			Null:       !.Flags.Has(3),
		},
		{
			Name:       "Media",
			SchemaName: "media",
			Null:       !.Flags.Has(5),
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *DraftMessage) () {
	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 ( *DraftMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode draftMessage#3fccf7ef as nil")
	}
	.PutID(DraftMessageTypeID)
	return .EncodeBare()
}

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

// Decode implements bin.Decoder.
func ( *DraftMessage) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode draftMessage#3fccf7ef to nil")
	}
	if  := .ConsumeID(DraftMessageTypeID);  != nil {
		return fmt.Errorf("unable to decode draftMessage#3fccf7ef: %w", )
	}
	return .DecodeBare()
}

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

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

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

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

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

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

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

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

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

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

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

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

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

// GetDate returns value of Date field.
func ( *DraftMessage) () ( int) {
	if  == nil {
		return
	}
	return .Date
}

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

// DraftMessageClassName is schema name of DraftMessageClass.
const DraftMessageClassName = "DraftMessage"

// DraftMessageClass represents DraftMessage generic type.
//
// See https://core.telegram.org/type/DraftMessage for reference.
//
// Example:
//
//	g, err := tg.DecodeDraftMessage(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.DraftMessageEmpty: // draftMessageEmpty#1b0c841a
//	case *tg.DraftMessage: // draftMessage#3fccf7ef
//	default: panic(v)
//	}
type DraftMessageClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() DraftMessageClass

	// TypeID returns type id in TL schema.
	//
	// See https://core.telegram.org/mtproto/TL-tl#remarks.
	TypeID() uint32
	// TypeName returns name of type in TL schema.
	TypeName() string
	// String implements fmt.Stringer.
	String() string
	// Zero returns true if current object has a zero value.
	Zero() bool

	// AsNotEmpty tries to map DraftMessageClass to DraftMessage.
	AsNotEmpty() (*DraftMessage, bool)
}

// AsNotEmpty tries to map DraftMessageEmpty to DraftMessage.
func ( *DraftMessageEmpty) () (*DraftMessage, bool) {
	return nil, false
}

// AsNotEmpty tries to map DraftMessage to DraftMessage.
func ( *DraftMessage) () (*DraftMessage, bool) {
	return , true
}

// DecodeDraftMessage implements binary de-serialization for DraftMessageClass.
func ( *bin.Buffer) (DraftMessageClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case DraftMessageEmptyTypeID:
		// Decoding draftMessageEmpty#1b0c841a.
		 := DraftMessageEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode DraftMessageClass: %w", )
		}
		return &, nil
	case DraftMessageTypeID:
		// Decoding draftMessage#3fccf7ef.
		 := DraftMessage{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode DraftMessageClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode DraftMessageClass: %w", bin.NewUnexpectedID())
	}
}

// DraftMessage boxes the DraftMessageClass providing a helper.
type DraftMessageBox struct {
	DraftMessage DraftMessageClass
}

// Decode implements bin.Decoder for DraftMessageBox.
func ( *DraftMessageBox) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("unable to decode DraftMessageBox to nil")
	}
	,  := DecodeDraftMessage()
	if  != nil {
		return fmt.Errorf("unable to decode boxed value: %w", )
	}
	.DraftMessage = 
	return nil
}

// Encode implements bin.Encode for DraftMessageBox.
func ( *DraftMessageBox) ( *bin.Buffer) error {
	if  == nil || .DraftMessage == nil {
		return fmt.Errorf("unable to encode DraftMessageClass as nil")
	}
	return .DraftMessage.Encode()
}