// Code generated by lark_sdk_gen. DO NOT EDIT.
/**
 * Copyright 2022 chyroc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package lark

import (
	"context"
	"io"
)

// UploadDriveFile 向云空间指定目录下上传一个小文件。
//
// 请不要使用这个接口上传大于20MB的文件, 如果有这个需求可以尝试使用[分片上传接口](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/multipart-upload-file-/introduction)。
// 该接口支持调用频率上限为5QPS
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_all
// new doc: https://open.feishu.cn/document/server-docs/docs/drive-v1/upload/upload_all
func (r *DriveService) UploadDriveFile(ctx context.Context, request *UploadDriveFileReq, options ...MethodOptionFunc) (*UploadDriveFileResp, *Response, error) {
	if r.cli.mock.mockDriveUploadDriveFile != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Drive#UploadDriveFile mock enable")
		return r.cli.mock.mockDriveUploadDriveFile(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "Drive",
		API:                   "UploadDriveFile",
		Method:                "POST",
		URL:                   r.cli.openBaseURL + "/open-apis/drive/v1/files/upload_all",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
		NeedUserAccessToken:   true,
		IsFile:                true,
	}
	resp := new(uploadDriveFileResp)

	response, err := r.cli.RawRequest(ctx, req, resp)
	return resp.Data, response, err
}

// MockDriveUploadDriveFile mock DriveUploadDriveFile method
func (r *Mock) MockDriveUploadDriveFile(f func(ctx context.Context, request *UploadDriveFileReq, options ...MethodOptionFunc) (*UploadDriveFileResp, *Response, error)) {
	r.mockDriveUploadDriveFile = f
}

// UnMockDriveUploadDriveFile un-mock DriveUploadDriveFile method
func (r *Mock) UnMockDriveUploadDriveFile() {
	r.mockDriveUploadDriveFile = nil
}

// UploadDriveFileReq ...
type UploadDriveFileReq struct {
	FileName   string    `json:"file_name,omitempty"`   // 文件名, 示例值: "demo.pdf", 最大长度: `250` 字符
	ParentType string    `json:"parent_type,omitempty"` // 上传点类型, 示例值: "explorer", 可选值有: explorer: 云空间。
	ParentNode string    `json:"parent_node,omitempty"` // 文件夹token, 获取方式见 [概述](https://open.feishu.cn/document/ukTMukTMukTM/uUDN04SN0QjL1QDN/files/guide/introduction), 示例值: "fldbcO1UuPz8VwnpPx5a92abcef"
	Size       int64     `json:"size,omitempty"`        // 文件大小（以字节为单位）, 示例值: 1024, 最大值: `20971520`
	Checksum   *string   `json:"checksum,omitempty"`    // 文件adler32校验和(可选), 示例值: "3248270248"
	File       io.Reader `json:"file,omitempty"`        // 文件二进制内容, 示例值: file binary
}

// UploadDriveFileResp ...
type UploadDriveFileResp struct {
	FileToken string `json:"file_token,omitempty"` // 新创建文件的 token
}

// uploadDriveFileResp ...
type uploadDriveFileResp struct {
	Code  int64                `json:"code,omitempty"` // 错误码, 非 0 表示失败
	Msg   string               `json:"msg,omitempty"`  // 错误描述
	Data  *UploadDriveFileResp `json:"data,omitempty"`
	Error *ErrorDetail         `json:"error,omitempty"`
}
