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

// UploadCDNFileReuploadNeeded represents TL type `upload.cdnFileReuploadNeeded#eea8e46e`.
// The file was cleared from the temporary RAM cache of the CDN¹ and has to be
// re-uploaded.
//
// Links:
//  1. https://core.telegram.org/cdn
//
// See https://core.telegram.org/constructor/upload.cdnFileReuploadNeeded for reference.
type UploadCDNFileReuploadNeeded struct {
	// Request token (see CDN¹)
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	RequestToken []byte
}

// UploadCDNFileReuploadNeededTypeID is TL type id of UploadCDNFileReuploadNeeded.
const UploadCDNFileReuploadNeededTypeID = 0xeea8e46e

// construct implements constructor of UploadCDNFileClass.
func ( UploadCDNFileReuploadNeeded) () UploadCDNFileClass { return & }

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

	_ UploadCDNFileClass = &UploadCDNFileReuploadNeeded{}
)

func ( *UploadCDNFileReuploadNeeded) () bool {
	if  == nil {
		return true
	}
	if !(.RequestToken == nil) {
		return false
	}

	return true
}

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

// FillFrom fills UploadCDNFileReuploadNeeded from given interface.
func ( *UploadCDNFileReuploadNeeded) ( interface {
	() ( []byte)
}) {
	.RequestToken = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *UploadCDNFileReuploadNeeded) () tdp.Type {
	 := tdp.Type{
		Name: "upload.cdnFileReuploadNeeded",
		ID:   UploadCDNFileReuploadNeededTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "RequestToken",
			SchemaName: "request_token",
		},
	}
	return 
}

// Encode implements bin.Encoder.
func ( *UploadCDNFileReuploadNeeded) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.cdnFileReuploadNeeded#eea8e46e as nil")
	}
	.PutID(UploadCDNFileReuploadNeededTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UploadCDNFileReuploadNeeded) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.cdnFileReuploadNeeded#eea8e46e as nil")
	}
	.PutBytes(.RequestToken)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *UploadCDNFileReuploadNeeded) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode upload.cdnFileReuploadNeeded#eea8e46e to nil")
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode upload.cdnFileReuploadNeeded#eea8e46e: field request_token: %w", )
		}
		.RequestToken = 
	}
	return nil
}

// GetRequestToken returns value of RequestToken field.
func ( *UploadCDNFileReuploadNeeded) () ( []byte) {
	if  == nil {
		return
	}
	return .RequestToken
}

// UploadCDNFile represents TL type `upload.cdnFile#a99fca4f`.
// Represent a chunk of a CDN¹ file.
//
// Links:
//  1. https://core.telegram.org/cdn
//
// See https://core.telegram.org/constructor/upload.cdnFile for reference.
type UploadCDNFile struct {
	// The data
	Bytes []byte
}

// UploadCDNFileTypeID is TL type id of UploadCDNFile.
const UploadCDNFileTypeID = 0xa99fca4f

// construct implements constructor of UploadCDNFileClass.
func ( UploadCDNFile) () UploadCDNFileClass { return & }

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

	_ UploadCDNFileClass = &UploadCDNFile{}
)

func ( *UploadCDNFile) () bool {
	if  == nil {
		return true
	}
	if !(.Bytes == nil) {
		return false
	}

	return true
}

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

// FillFrom fills UploadCDNFile from given interface.
func ( *UploadCDNFile) ( interface {
	() ( []byte)
}) {
	.Bytes = .()
}

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

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

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

// Encode implements bin.Encoder.
func ( *UploadCDNFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.cdnFile#a99fca4f as nil")
	}
	.PutID(UploadCDNFileTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UploadCDNFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.cdnFile#a99fca4f as nil")
	}
	.PutBytes(.Bytes)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *UploadCDNFile) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode upload.cdnFile#a99fca4f to nil")
	}
	{
		,  := .Bytes()
		if  != nil {
			return fmt.Errorf("unable to decode upload.cdnFile#a99fca4f: field bytes: %w", )
		}
		.Bytes = 
	}
	return nil
}

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

// UploadCDNFileClassName is schema name of UploadCDNFileClass.
const UploadCDNFileClassName = "upload.CdnFile"

// UploadCDNFileClass represents upload.CdnFile generic type.
//
// See https://core.telegram.org/type/upload.CdnFile for reference.
//
// Example:
//
//	g, err := tg.DecodeUploadCDNFile(buf)
//	if err != nil {
//	    panic(err)
//	}
//	switch v := g.(type) {
//	case *tg.UploadCDNFileReuploadNeeded: // upload.cdnFileReuploadNeeded#eea8e46e
//	case *tg.UploadCDNFile: // upload.cdnFile#a99fca4f
//	default: panic(v)
//	}
type UploadCDNFileClass interface {
	bin.Encoder
	bin.Decoder
	bin.BareEncoder
	bin.BareDecoder
	construct() UploadCDNFileClass

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

// DecodeUploadCDNFile implements binary de-serialization for UploadCDNFileClass.
func ( *bin.Buffer) (UploadCDNFileClass, error) {
	,  := .PeekID()
	if  != nil {
		return nil, 
	}
	switch  {
	case UploadCDNFileReuploadNeededTypeID:
		// Decoding upload.cdnFileReuploadNeeded#eea8e46e.
		 := UploadCDNFileReuploadNeeded{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UploadCDNFileClass: %w", )
		}
		return &, nil
	case UploadCDNFileTypeID:
		// Decoding upload.cdnFile#a99fca4f.
		 := UploadCDNFile{}
		if  := .Decode();  != nil {
			return nil, fmt.Errorf("unable to decode UploadCDNFileClass: %w", )
		}
		return &, nil
	default:
		return nil, fmt.Errorf("unable to decode UploadCDNFileClass: %w", bin.NewUnexpectedID())
	}
}

// UploadCDNFile boxes the UploadCDNFileClass providing a helper.
type UploadCDNFileBox struct {
	CdnFile UploadCDNFileClass
}

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

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