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

// UploadFile represents TL type `upload.file#96a18d5`.
// File content.
//
// See https://core.telegram.org/constructor/upload.file for reference.
type UploadFile struct {
	// File type
	Type StorageFileTypeClass
	// Modification time
	Mtime int
	// Binary data, file content
	Bytes []byte
}

// UploadFileTypeID is TL type id of UploadFile.
const UploadFileTypeID = 0x96a18d5

// construct implements constructor of UploadFileClass.
func ( UploadFile) () UploadFileClass { return & }

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

	_ UploadFileClass = &UploadFile{}
)

func ( *UploadFile) () bool {
	if  == nil {
		return true
	}
	if !(.Type == nil) {
		return false
	}
	if !(.Mtime == 0) {
		return false
	}
	if !(.Bytes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills UploadFile from given interface.
func ( *UploadFile) ( interface {
	() ( StorageFileTypeClass)
	() ( int)
	() ( []byte)
}) {
	.Type = .()
	.Mtime = .()
	.Bytes = .()
}

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

// TypeName returns name of type in TL schema.
func (*UploadFile) () string {
	return "upload.file"
}

// TypeInfo returns info about TL type.
func ( *UploadFile) () tdp.Type {
	 := tdp.Type{
		Name: "upload.file",
		ID:   UploadFileTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Type",
			SchemaName: "type",
		},
		{
			Name:       "Mtime",
			SchemaName: "mtime",
		},
		{
			Name:       "Bytes",
			SchemaName: "bytes",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *UploadFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.file#96a18d5 as nil")
	}
	.PutID(UploadFileTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UploadFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.file#96a18d5 as nil")
	}
	if .Type == nil {
		return fmt.Errorf("unable to encode upload.file#96a18d5: field type is nil")
	}
	if  := .Type.Encode();  != nil {
		return fmt.Errorf("unable to encode upload.file#96a18d5: field type: %w", )
	}
	.PutInt(.Mtime)
	.PutBytes(.Bytes)
	return nil
}

// Decode implements bin.Decoder.
func ( *UploadFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode upload.file#96a18d5 to nil")
	}
	if  := .ConsumeID(UploadFileTypeID);  != nil {
		return fmt.Errorf("unable to decode upload.file#96a18d5: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *UploadFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode upload.file#96a18d5 to nil")
	}
	{
		,  := DecodeStorageFileType()
		if  != nil {
			return fmt.Errorf("unable to decode upload.file#96a18d5: field type: %w", )
		}
		.Type = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode upload.file#96a18d5: field mtime: %w", )
		}
		.Mtime = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode upload.file#96a18d5: field bytes: %w", )
		}
		.Bytes = 
	}
	return nil
}

// GetType returns value of Type field.
func ( *UploadFile) () ( StorageFileTypeClass) {
	if  == nil {
		return
	}
	return .Type
}

// GetMtime returns value of Mtime field.
func ( *UploadFile) () ( int) {
	if  == nil {
		return
	}
	return .Mtime
}

// GetBytes returns value of Bytes field.
func ( *UploadFile) () ( []byte) {
	if  == nil {
		return
	}
	return .Bytes
}

// UploadFileCDNRedirect represents TL type `upload.fileCdnRedirect#f18cda44`.
// The file must be downloaded from a CDN DC¹.
//
// Links:
//  1. https://core.telegram.org/cdn
//
// See https://core.telegram.org/constructor/upload.fileCdnRedirect for reference.
type UploadFileCDNRedirect struct {
	// CDN DC¹ ID
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	DCID int
	// File token (see CDN files¹)
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	FileToken []byte
	// Encryption key (see CDN files¹)
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	EncryptionKey []byte
	// Encryption IV (see CDN files¹)
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	EncryptionIv []byte
	// File hashes (see CDN files¹)
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	FileHashes []FileHash
}

// UploadFileCDNRedirectTypeID is TL type id of UploadFileCDNRedirect.
const UploadFileCDNRedirectTypeID = 0xf18cda44

// construct implements constructor of UploadFileClass.
func ( UploadFileCDNRedirect) () UploadFileClass { return & }

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

	_ UploadFileClass = &UploadFileCDNRedirect{}
)

func ( *UploadFileCDNRedirect) () bool {
	if  == nil {
		return true
	}
	if !(.DCID == 0) {
		return false
	}
	if !(.FileToken == nil) {
		return false
	}
	if !(.EncryptionKey == nil) {
		return false
	}
	if !(.EncryptionIv == nil) {
		return false
	}
	if !(.FileHashes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills UploadFileCDNRedirect from given interface.
func ( *UploadFileCDNRedirect) ( interface {
	() ( int)
	() ( []byte)
	() ( []byte)
	() ( []byte)
	() ( []FileHash)
}) {
	.DCID = .()
	.FileToken = .()
	.EncryptionKey = .()
	.EncryptionIv = .()
	.FileHashes = .()
}

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

// TypeName returns name of type in TL schema.
func (*UploadFileCDNRedirect) () string {
	return "upload.fileCdnRedirect"
}

// TypeInfo returns info about TL type.
func ( *UploadFileCDNRedirect) () tdp.Type {
	 := tdp.Type{
		Name: "upload.fileCdnRedirect",
		ID:   UploadFileCDNRedirectTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "DCID",
			SchemaName: "dc_id",
		},
		{
			Name:       "FileToken",
			SchemaName: "file_token",
		},
		{
			Name:       "EncryptionKey",
			SchemaName: "encryption_key",
		},
		{
			Name:       "EncryptionIv",
			SchemaName: "encryption_iv",
		},
		{
			Name:       "FileHashes",
			SchemaName: "file_hashes",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *UploadFileCDNRedirect) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.fileCdnRedirect#f18cda44 as nil")
	}
	.PutID(UploadFileCDNRedirectTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UploadFileCDNRedirect) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.fileCdnRedirect#f18cda44 as nil")
	}
	.PutInt(.DCID)
	.PutBytes(.FileToken)
	.PutBytes(.EncryptionKey)
	.PutBytes(.EncryptionIv)
	.PutVectorHeader(len(.FileHashes))
	for ,  := range .FileHashes {
		if  := .Encode();  != nil {
			return fmt.Errorf("unable to encode upload.fileCdnRedirect#f18cda44: field file_hashes element with index %d: %w", , )
		}
	}
	return nil
}

// Decode implements bin.Decoder.
func ( *UploadFileCDNRedirect) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode upload.fileCdnRedirect#f18cda44 to nil")
	}
	if  := .ConsumeID(UploadFileCDNRedirectTypeID);  != nil {
		return fmt.Errorf("unable to decode upload.fileCdnRedirect#f18cda44: %w", )
	}
	return .DecodeBare()
}

// DecodeBare implements bin.BareDecoder.
func ( *UploadFileCDNRedirect) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode upload.fileCdnRedirect#f18cda44 to nil")
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode upload.fileCdnRedirect#f18cda44: field dc_id: %w", )
		}
		.DCID = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode upload.fileCdnRedirect#f18cda44: field file_token: %w", )
		}
		.FileToken = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode upload.fileCdnRedirect#f18cda44: field encryption_key: %w", )
		}
		.EncryptionKey = 
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode upload.fileCdnRedirect#f18cda44: field encryption_iv: %w", )
		}
		.EncryptionIv = 
	}
	{
		,  := .VectorHeader()
		if  != nil {
			return fmt.Errorf("unable to decode upload.fileCdnRedirect#f18cda44: field file_hashes: %w", )
		}

		if  > 0 {
			.FileHashes = make([]FileHash, 0, %bin.PreallocateLimit)
		}
		for  := 0;  < ; ++ {
			var  FileHash
			if  := .Decode();  != nil {
				return fmt.Errorf("unable to decode upload.fileCdnRedirect#f18cda44: field file_hashes: %w", )
			}
			.FileHashes = append(.FileHashes, )
		}
	}
	return nil
}

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

// GetFileToken returns value of FileToken field.
func ( *UploadFileCDNRedirect) () ( []byte) {
	if  == nil {
		return
	}
	return .FileToken
}

// GetEncryptionKey returns value of EncryptionKey field.
func ( *UploadFileCDNRedirect) () ( []byte) {
	if  == nil {
		return
	}
	return .EncryptionKey
}

// GetEncryptionIv returns value of EncryptionIv field.
func ( *UploadFileCDNRedirect) () ( []byte) {
	if  == nil {
		return
	}
	return .EncryptionIv
}

// GetFileHashes returns value of FileHashes field.
func ( *UploadFileCDNRedirect) () ( []FileHash) {
	if  == nil {
		return
	}
	return .FileHashes
}

// UploadFileClassName is schema name of UploadFileClass.
const UploadFileClassName = "upload.File"

// UploadFileClass represents upload.File generic type.
//
// See https://core.telegram.org/type/upload.File for reference.
//
// Example:
//
//	g, err := tg.DecodeUploadFile(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.UploadFile: // upload.file#96a18d5
//	case *tg.UploadFileCDNRedirect: // upload.fileCdnRedirect#f18cda44
//	default: panic(v)
//	}
type UploadFileClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() UploadFileClass

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

// DecodeUploadFile implements binary de-serialization for UploadFileClass.
func ( *bin.Buffer) (UploadFileClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case UploadFileTypeID:
		// Decoding upload.file#96a18d5.
		 := UploadFile{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UploadFileClass: %w", )
		}
		return &, nil
	case UploadFileCDNRedirectTypeID:
		// Decoding upload.fileCdnRedirect#f18cda44.
		 := UploadFileCDNRedirect{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UploadFileClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode UploadFileClass: %w", bin.NewUnexpectedID())
	}
}

// UploadFile boxes the UploadFileClass providing a helper.
type UploadFileBox struct {
	File UploadFileClass
}

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

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