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

// DocumentEmpty represents TL type `documentEmpty#36f8c871`.
// Empty constructor, document doesn't exist.
//
// See https://core.telegram.org/constructor/documentEmpty for reference.
type DocumentEmpty struct {
	// Document ID or 0
	ID int64
}

// DocumentEmptyTypeID is TL type id of DocumentEmpty.
const DocumentEmptyTypeID = 0x36f8c871

// construct implements constructor of DocumentClass.
func ( DocumentEmpty) () DocumentClass { return & }

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

	_ DocumentClass = &DocumentEmpty{}
)

func ( *DocumentEmpty) () bool {
	if  == nil {
		return true
	}
	if !(.ID == 0) {
		return false
	}

	return true
}

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

// FillFrom fills DocumentEmpty from given interface.
func ( *DocumentEmpty) ( interface {
	() ( int64)
}) {
	.ID = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *DocumentEmpty) () tdp.Type {
	 := tdp.Type{
		Name: "documentEmpty",
		ID:   DocumentEmptyTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *DocumentEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode documentEmpty#36f8c871 as nil")
	}
	.PutID(DocumentEmptyTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *DocumentEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode documentEmpty#36f8c871 as nil")
	}
	.PutLong(.ID)
	return nil
}

// Decode implements bin.Decoder.
func ( *DocumentEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode documentEmpty#36f8c871 to nil")
	}
	if  := .ConsumeID(DocumentEmptyTypeID);  != nil {
		return fmt.Errorf("unable to decode documentEmpty#36f8c871: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *DocumentEmpty) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode documentEmpty#36f8c871 to nil")
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode documentEmpty#36f8c871: field id: %w", )
		}
		.ID = 
	}
	return nil
}

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

// Document represents TL type `document#8fd4c4d8`.
// Document
//
// See https://core.telegram.org/constructor/document for reference.
type Document struct {
	// Flags, see TL conditional fieldsĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Document ID
	ID int64
	// Check sum, dependent on document ID
	AccessHash int64
	// File referenceĀ¹
	//
	// Links:
	//  1) https://core.telegram.org/api/file_reference
	FileReference []byte
	// Creation date
	Date int
	// MIME type
	MimeType string
	// Size
	Size int64
	// Thumbnails
	//
	// Use SetThumbs and GetThumbs helpers.
	Thumbs []PhotoSizeClass
	// Video thumbnails
	//
	// Use SetVideoThumbs and GetVideoThumbs helpers.
	VideoThumbs []VideoSizeClass
	// DC ID
	DCID int
	// Attributes
	Attributes []DocumentAttributeClass
}

// DocumentTypeID is TL type id of Document.
const DocumentTypeID = 0x8fd4c4d8

// construct implements constructor of DocumentClass.
func ( Document) () DocumentClass { return & }

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

	_ DocumentClass = &Document{}
)

func ( *Document) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.ID == 0) {
		return false
	}
	if !(.AccessHash == 0) {
		return false
	}
	if !(.FileReference == nil) {
		return false
	}
	if !(.Date == 0) {
		return false
	}
	if !(.MimeType == "") {
		return false
	}
	if !(.Size == 0) {
		return false
	}
	if !(.Thumbs == nil) {
		return false
	}
	if !(.VideoThumbs == nil) {
		return false
	}
	if !(.DCID == 0) {
		return false
	}
	if !(.Attributes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills Document from given interface.
func ( *Document) ( interface {
	() ( int64)
	() ( int64)
	() ( []byte)
	() ( int)
	() ( string)
	() ( int64)
	() ( []PhotoSizeClass,  bool)
	() ( []VideoSizeClass,  bool)
	() ( int)
	() ( []DocumentAttributeClass)
}) {
	.ID = .()
	.AccessHash = .()
	.FileReference = .()
	.Date = .()
	.MimeType = .()
	.Size = .()
	if ,  := .();  {
		.Thumbs = 
	}

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

	.DCID = .()
	.Attributes = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *Document) () tdp.Type {
	 := tdp.Type{
		Name: "document",
		ID:   DocumentTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "ID",
			SchemaName: "id",
		},
		{
			Name:       "AccessHash",
			SchemaName: "access_hash",
		},
		{
			Name:       "FileReference",
			SchemaName: "file_reference",
		},
		{
			Name:       "Date",
			SchemaName: "date",
		},
		{
			Name:       "MimeType",
			SchemaName: "mime_type",
		},
		{
			Name:       "Size",
			SchemaName: "size",
		},
		{
			Name:       "Thumbs",
			SchemaName: "thumbs",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "VideoThumbs",
			SchemaName: "video_thumbs",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
		{
			Name:       "Attributes",
			SchemaName: "attributes",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *Document) () {
	if !(.Thumbs == nil) {
		.Flags.Set(0)
	}
	if !(.VideoThumbs == nil) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *Document) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode document#8fd4c4d8 as nil")
	}
	.PutID(DocumentTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *Document) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode document#8fd4c4d8 as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode document#8fd4c4d8: field flags: %w", )
	}
	.PutLong(.ID)
	.PutLong(.AccessHash)
	.PutBytes(.FileReference)
	.PutInt(.Date)
	.PutString(.MimeType)
	.PutLong(.Size)
	if .Flags.Has(0) {
		.PutVectorHeader(len(.Thumbs))
		for ,  := range .Thumbs {
			if  == nil {
				return fmt.Errorf("unable to encode document#8fd4c4d8: field thumbs element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode document#8fd4c4d8: field thumbs element with index %d: %w", , )
			}
		}
	}
	if .Flags.Has(1) {
		.PutVectorHeader(len(.VideoThumbs))
		for ,  := range .VideoThumbs {
			if  == nil {
				return fmt.Errorf("unable to encode document#8fd4c4d8: field video_thumbs element with index %d is nil", )
			}
			if  := .Encode();  != nil {
				return fmt.Errorf("unable to encode document#8fd4c4d8: field video_thumbs element with index %d: %w", , )
			}
		}
	}
	.PutInt(.DCID)
	.PutVectorHeader(len(.Attributes))
	for ,  := range .Attributes {
		if  == nil {
			return fmt.Errorf("unable to encode document#8fd4c4d8: field attributes element with index %d is nil", )
		}
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode document#8fd4c4d8: field attributes element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *Document) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode document#8fd4c4d8 to nil")
	}
	if  := .ConsumeID(DocumentTypeID);  != nil {
		return fmt.Errorf("unable to decode document#8fd4c4d8: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *Document) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode document#8fd4c4d8 to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field flags: %w", )
		}
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field id: %w", )
		}
		.ID = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field access_hash: %w", )
		}
		.AccessHash = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field file_reference: %w", )
		}
		.FileReference = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field date: %w", )
		}
		.Date = 
	}
	{
		,  := .String()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field mime_type: %w", )
		}
		.MimeType = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field size: %w", )
		}
		.Size = 
	}
	if .Flags.Has(0) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field thumbs: %w", )
		}

		if  > 0 {
			.Thumbs = make([]PhotoSizeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodePhotoSize()
			if  != nil {
				return fmt.Errorf("unable to decode document#8fd4c4d8: field thumbs: %w", )
			}
			.Thumbs = append(.Thumbs, )
		}
	}
	if .Flags.Has(1) {
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field video_thumbs: %w", )
		}

		if  > 0 {
			.VideoThumbs = make([]VideoSizeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeVideoSize()
			if  != nil {
				return fmt.Errorf("unable to decode document#8fd4c4d8: field video_thumbs: %w", )
			}
			.VideoThumbs = append(.VideoThumbs, )
		}
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field dc_id: %w", )
		}
		.DCID = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode document#8fd4c4d8: field attributes: %w", )
		}

		if  > 0 {
			.Attributes = make([]DocumentAttributeClass, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			,  := DecodeDocumentAttribute()
			if  != nil {
				return fmt.Errorf("unable to decode document#8fd4c4d8: field attributes: %w", )
			}
			.Attributes = append(.Attributes, )
		}
	}
	return nil
}

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

// GetAccessHash returns value of AccessHash field.
func ( *Document) () ( int64) {
	if  == nil {
		return
	}
	return .AccessHash
}

// GetFileReference returns value of FileReference field.
func ( *Document) () ( []byte) {
	if  == nil {
		return
	}
	return .FileReference
}

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

// GetMimeType returns value of MimeType field.
func ( *Document) () ( string) {
	if  == nil {
		return
	}
	return .MimeType
}

// GetSize returns value of Size field.
func ( *Document) () ( int64) {
	if  == nil {
		return
	}
	return .Size
}

// SetThumbs sets value of Thumbs conditional field.
func ( *Document) ( []PhotoSizeClass) {
	.Flags.Set(0)
	.Thumbs = 
}

// GetThumbs returns value of Thumbs conditional field and
// boolean which is true if field was set.
func ( *Document) () ( []PhotoSizeClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(0) {
		return , false
	}
	return .Thumbs, true
}

// SetVideoThumbs sets value of VideoThumbs conditional field.
func ( *Document) ( []VideoSizeClass) {
	.Flags.Set(1)
	.VideoThumbs = 
}

// GetVideoThumbs returns value of VideoThumbs conditional field and
// boolean which is true if field was set.
func ( *Document) () ( []VideoSizeClass,  bool) {
	if  == nil {
		return
	}
	if !.Flags.Has(1) {
		return , false
	}
	return .VideoThumbs, true
}

// GetDCID returns value of DCID field.
func ( *Document) () ( int) {
	if  == nil {
		return
	}
	return .DCID
}

// GetAttributes returns value of Attributes field.
func ( *Document) () ( []DocumentAttributeClass) {
	if  == nil {
		return
	}
	return .Attributes
}

// MapThumbs returns field Thumbs wrapped in PhotoSizeClassArray helper.
func ( *Document) () ( PhotoSizeClassArray,  bool) {
	if !.Flags.Has(0) {
		return , false
	}
	return PhotoSizeClassArray(.Thumbs), true
}

// MapVideoThumbs returns field VideoThumbs wrapped in VideoSizeClassArray helper.
func ( *Document) () ( VideoSizeClassArray,  bool) {
	if !.Flags.Has(1) {
		return , false
	}
	return VideoSizeClassArray(.VideoThumbs), true
}

// MapAttributes returns field Attributes wrapped in DocumentAttributeClassArray helper.
func ( *Document) () ( DocumentAttributeClassArray) {
	return DocumentAttributeClassArray(.Attributes)
}

// DocumentClassName is schema name of DocumentClass.
const DocumentClassName = "Document"

// DocumentClass represents Document generic type.
//
// See https://core.telegram.org/type/Document for reference.
//
// Example:
//
//	g, err := tg.DecodeDocument(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.DocumentEmpty: // documentEmpty#36f8c871
//	case *tg.Document: // document#8fd4c4d8
//	default: panic(v)
//	}
type DocumentClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() DocumentClass

	// 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

	// Document ID or 0
	GetID() (value int64)

	// AsNotEmpty tries to map DocumentClass to Document.
	AsNotEmpty() (*Document, bool)
}

// AsInputDocumentFileLocation tries to map Document to InputDocumentFileLocation.
func ( *Document) () *InputDocumentFileLocation {
	 := new(InputDocumentFileLocation)
	.ID = .GetID()
	.AccessHash = .GetAccessHash()
	.FileReference = .GetFileReference()

	return 
}

// AsInput tries to map Document to InputDocument.
func ( *Document) () *InputDocument {
	 := new(InputDocument)
	.ID = .GetID()
	.AccessHash = .GetAccessHash()
	.FileReference = .GetFileReference()

	return 
}

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

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

// DecodeDocument implements binary de-serialization for DocumentClass.
func ( *bin.Buffer) (DocumentClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case DocumentEmptyTypeID:
		// Decoding documentEmpty#36f8c871.
		 := DocumentEmpty{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode DocumentClass: %w", )
		}
		return &, nil
	case DocumentTypeID:
		// Decoding document#8fd4c4d8.
		 := Document{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode DocumentClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode DocumentClass: %w", bin.NewUnexpectedID())
	}
}

// Document boxes the DocumentClass providing a helper.
type DocumentBox struct {
	Document DocumentClass
}

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

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