package downloader

import (
	
	

	

	
)

// RedirectError error is returned when Downloader get CDN redirect.
// See https://core.telegram.org/constructor/upload.fileCdnRedirect.
type RedirectError struct {
	Redirect *tg.UploadFileCDNRedirect
}

// Error implements error interface.
func ( *RedirectError) () string {
	return "redirect to CDN DC " + strconv.Itoa(.Redirect.DCID)
}

// master is a master DC download schema.
// See https://core.telegram.org/api/files#downloading-files.
type master struct {
	client Client

	precise  bool
	allowCDN bool
	// retryHandler observes retried transient downloader errors.
	retryHandler RetryHandler
	location     tg.InputFileLocationClass
}

var _ schema = master{}

func ( master) ( string,  int,  error) {
	if  < 1 ||  == nil || .retryHandler == nil {
		return
	}
	.retryHandler(RetryEvent{
		Operation: ,
		Attempt:   ,
		Err:       ,
	})
}

func ( master) ( context.Context,  int64,  int) (chunk, error) {
	 := &tg.UploadGetFileRequest{
		Offset:   ,
		Limit:    ,
		Location: .location,
	}
	.SetCDNSupported(.allowCDN)
	.SetPrecise(.precise)

	,  := .client.UploadGetFile(, )
	if  != nil {
		return chunk{}, 
	}

	switch result := .(type) {
	case *tg.UploadFile:
		return chunk{data: .Bytes, tag: .Type}, nil
	case *tg.UploadFileCDNRedirect:
		return chunk{}, &RedirectError{Redirect: }
	default:
		return chunk{}, errors.Errorf("unexpected type %T", )
	}
}

func ( master) ( context.Context,  int64) ([]tg.FileHash, error) {
	return .client.UploadGetFileHashes(, &tg.UploadGetFileHashesRequest{
		Location: .location,
		Offset:   ,
	})
}