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

// UploadGetFileRequest represents TL type `upload.getFile#be5335be`.
// Returns content of a whole file or its part.
//
// See https://core.telegram.org/method/upload.getFile for reference.
type UploadGetFileRequest struct {
	// Flags, see TL conditional fields¹
	//
	// Links:
	//  1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
	Flags bin.Fields
	// Disable some checks on limit and offset values, useful for example to stream videos by
	// keyframes
	Precise bool
	// Whether the current client supports CDN downloads¹
	//
	// Links:
	//  1) https://core.telegram.org/cdn
	CDNSupported bool
	// File location
	Location InputFileLocationClass
	// Number of bytes to be skipped
	Offset int64
	// Number of bytes to be returned
	Limit int
}

// UploadGetFileRequestTypeID is TL type id of UploadGetFileRequest.
const UploadGetFileRequestTypeID = 0xbe5335be

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

func ( *UploadGetFileRequest) () bool {
	if  == nil {
		return true
	}
	if !(.Flags.Zero()) {
		return false
	}
	if !(.Precise == false) {
		return false
	}
	if !(.CDNSupported == false) {
		return false
	}
	if !(.Location == nil) {
		return false
	}
	if !(.Offset == 0) {
		return false
	}
	if !(.Limit == 0) {
		return false
	}

	return true
}

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

// FillFrom fills UploadGetFileRequest from given interface.
func ( *UploadGetFileRequest) ( interface {
	() ( bool)
	() ( bool)
	() ( InputFileLocationClass)
	() ( int64)
	() ( int)
}) {
	.Precise = .()
	.CDNSupported = .()
	.Location = .()
	.Offset = .()
	.Limit = .()
}

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

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

// TypeInfo returns info about TL type.
func ( *UploadGetFileRequest) () tdp.Type {
	 := tdp.Type{
		Name: "upload.getFile",
		ID:   UploadGetFileRequestTypeID,
	}
	if  == nil {
		.Null = true
		return 
	}
	.Fields = []tdp.Field{
		{
			Name:       "Precise",
			SchemaName: "precise",
			Null:       !.Flags.Has(0),
		},
		{
			Name:       "CDNSupported",
			SchemaName: "cdn_supported",
			Null:       !.Flags.Has(1),
		},
		{
			Name:       "Location",
			SchemaName: "location",
		},
		{
			Name:       "Offset",
			SchemaName: "offset",
		},
		{
			Name:       "Limit",
			SchemaName: "limit",
		},
	}
	return 
}

// SetFlags sets flags for non-zero fields.
func ( *UploadGetFileRequest) () {
	if !(.Precise == false) {
		.Flags.Set(0)
	}
	if !(.CDNSupported == false) {
		.Flags.Set(1)
	}
}

// Encode implements bin.Encoder.
func ( *UploadGetFileRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.getFile#be5335be as nil")
	}
	.PutID(UploadGetFileRequestTypeID)
	return .EncodeBare()
}

// EncodeBare implements bin.BareEncoder.
func ( *UploadGetFileRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't encode upload.getFile#be5335be as nil")
	}
	.SetFlags()
	if  := .Flags.Encode();  != nil {
		return fmt.Errorf("unable to encode upload.getFile#be5335be: field flags: %w", )
	}
	if .Location == nil {
		return fmt.Errorf("unable to encode upload.getFile#be5335be: field location is nil")
	}
	if  := .Location.Encode();  != nil {
		return fmt.Errorf("unable to encode upload.getFile#be5335be: field location: %w", )
	}
	.PutLong(.Offset)
	.PutInt(.Limit)
	return nil
}

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

// DecodeBare implements bin.BareDecoder.
func ( *UploadGetFileRequest) ( *bin.Buffer) error {
	if  == nil {
		return fmt.Errorf("can't decode upload.getFile#be5335be to nil")
	}
	{
		if  := .Flags.Decode();  != nil {
			return fmt.Errorf("unable to decode upload.getFile#be5335be: field flags: %w", )
		}
	}
	.Precise = .Flags.Has(0)
	.CDNSupported = .Flags.Has(1)
	{
		,  := DecodeInputFileLocation()
		if  != nil {
			return fmt.Errorf("unable to decode upload.getFile#be5335be: field location: %w", )
		}
		.Location = 
	}
	{
		,  := .Long()
		if  != nil {
			return fmt.Errorf("unable to decode upload.getFile#be5335be: field offset: %w", )
		}
		.Offset = 
	}
	{
		,  := .Int()
		if  != nil {
			return fmt.Errorf("unable to decode upload.getFile#be5335be: field limit: %w", )
		}
		.Limit = 
	}
	return nil
}

// SetPrecise sets value of Precise conditional field.
func ( *UploadGetFileRequest) ( bool) {
	if  {
		.Flags.Set(0)
		.Precise = true
	} else {
		.Flags.Unset(0)
		.Precise = false
	}
}

// GetPrecise returns value of Precise conditional field.
func ( *UploadGetFileRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(0)
}

// SetCDNSupported sets value of CDNSupported conditional field.
func ( *UploadGetFileRequest) ( bool) {
	if  {
		.Flags.Set(1)
		.CDNSupported = true
	} else {
		.Flags.Unset(1)
		.CDNSupported = false
	}
}

// GetCDNSupported returns value of CDNSupported conditional field.
func ( *UploadGetFileRequest) () ( bool) {
	if  == nil {
		return
	}
	return .Flags.Has(1)
}

// GetLocation returns value of Location field.
func ( *UploadGetFileRequest) () ( InputFileLocationClass) {
	if  == nil {
		return
	}
	return .Location
}

// GetOffset returns value of Offset field.
func ( *UploadGetFileRequest) () ( int64) {
	if  == nil {
		return
	}
	return .Offset
}

// GetLimit returns value of Limit field.
func ( *UploadGetFileRequest) () ( int) {
	if  == nil {
		return
	}
	return .Limit
}

// UploadGetFile invokes method upload.getFile#be5335be returning error if any.
// Returns content of a whole file or its part.
//
// Possible errors:
//
//	400 CDN_METHOD_INVALID: You can't call this method in a CDN DC.
//	400 CHANNEL_INVALID: The provided channel is invalid.
//	400 CHANNEL_PRIVATE: You haven't joined this channel/supergroup.
//	406 FILEREF_UPGRADE_NEEDED: The client has to be updated in order to support file references.
//	400 FILE_ID_INVALID: The provided file id is invalid.
//	400 FILE_REFERENCE_*: The file reference expired, it must be refreshed.
//	400 FILE_REFERENCE_EXPIRED: File reference expired, it must be refetched as described in the documentation.
//	400 LIMIT_INVALID: The provided limit is invalid.
//	400 LOCATION_INVALID: The provided location is invalid.
//	400 MSG_ID_INVALID: Invalid message ID provided.
//	400 OFFSET_INVALID: The provided offset is invalid.
//	400 PEER_ID_INVALID: The provided peer id is invalid.
//
// See https://core.telegram.org/method/upload.getFile for reference.
// Can be used by bots.
func ( *Client) ( context.Context,  *UploadGetFileRequest) (UploadFileClass, error) {
	var  UploadFileBox

	if  := .rpc.Invoke(, , &);  != nil {
		return nil, 
	}
	return .File, nil
}