// 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"
)

// PrepareUploadDriveFile 发送初始化请求, 以获取上传事务 ID 和分片策略, 为[上传分片](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_part)做准备。平台固定以 4MB 的大小对文件进行分片。了解完整的上传文件流程, 参考[上传文件概述](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/multipart-upload-file-/introduction)。
//
// 注意事项:
// 上传事务 ID 和上传进度在 24 小时内有效。请及时保存和恢复上传。
// 使用限制:
// 该接口不支持并发调用, 且调用频率上限为 5 QPS, 10000 次/天。否则会返回 1061045 错误码, 可通过稍后重试解决。
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/file/upload_prepare
// new doc: https://open.feishu.cn/document/server-docs/docs/drive-v1/upload/multipart-upload-file-/upload_prepare
func (r *DriveService) PrepareUploadDriveFile(ctx context.Context, request *PrepareUploadDriveFileReq, options ...MethodOptionFunc) (*PrepareUploadDriveFileResp, *Response, error) {
	if r.cli.mock.mockDrivePrepareUploadDriveFile != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Drive#PrepareUploadDriveFile mock enable")
		return r.cli.mock.mockDrivePrepareUploadDriveFile(ctx, request, options...)
	}

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

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

// MockDrivePrepareUploadDriveFile mock DrivePrepareUploadDriveFile method
func (r *Mock) MockDrivePrepareUploadDriveFile(f func(ctx context.Context, request *PrepareUploadDriveFileReq, options ...MethodOptionFunc) (*PrepareUploadDriveFileResp, *Response, error)) {
	r.mockDrivePrepareUploadDriveFile = f
}

// UnMockDrivePrepareUploadDriveFile un-mock DrivePrepareUploadDriveFile method
func (r *Mock) UnMockDrivePrepareUploadDriveFile() {
	r.mockDrivePrepareUploadDriveFile = nil
}

// PrepareUploadDriveFileReq ...
type PrepareUploadDriveFileReq struct {
	FileName   string `json:"file_name,omitempty"`   // 文件的名称, 示例值: "test.txt", 最大长度: `250` 字符
	ParentType string `json:"parent_type,omitempty"` // 上传点的类型。取固定值 explorer, 表示将文件上传至云空间中, 示例值: "explorer", 可选值有: explorer: 云空间
	ParentNode string `json:"parent_node,omitempty"` // 云空间中文件夹的 token。了解如何获取文件夹 token, 参考[文件夹概述](https://open.feishu.cn/document/ukTMukTMukTM/ugTNzUjL4UzM14CO1MTN/folder-overview), 示例值: "fldbcO1UuPz8VwnpPx5a92abcef"
	Size       int64  `json:"size,omitempty"`        // 文件的大小, 单位为字节, 示例值: 1024, 最小值: `0`
}

// PrepareUploadDriveFileResp ...
type PrepareUploadDriveFileResp struct {
	UploadID  string `json:"upload_id,omitempty"`  // 分片上传事务 ID
	BlockSize int64  `json:"block_size,omitempty"` // 分片大小策略
	BlockNum  int64  `json:"block_num,omitempty"`  // 分片的数量
}

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