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

// PartUploadDriveMedia 根据 [预上传](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/media/upload_prepare)接口返回的上传事务 ID 和分片策略上传对应的素材分片。上传完成后, 你可调用 [分片上传素材（完成上传）](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/media/upload_finish)触发完成上传。
//
// 该接口不支持较高并发, 且调用频率上限为 5 QPS。
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/media/upload_part
// new doc: https://open.feishu.cn/document/server-docs/docs/drive-v1/media/multipart-upload-media/upload_part
func (r *DriveService) PartUploadDriveMedia(ctx context.Context, request *PartUploadDriveMediaReq, options ...MethodOptionFunc) (*PartUploadDriveMediaResp, *Response, error) {
	if r.cli.mock.mockDrivePartUploadDriveMedia != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Drive#PartUploadDriveMedia mock enable")
		return r.cli.mock.mockDrivePartUploadDriveMedia(ctx, request, options...)
	}

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

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

// MockDrivePartUploadDriveMedia mock DrivePartUploadDriveMedia method
func (r *Mock) MockDrivePartUploadDriveMedia(f func(ctx context.Context, request *PartUploadDriveMediaReq, options ...MethodOptionFunc) (*PartUploadDriveMediaResp, *Response, error)) {
	r.mockDrivePartUploadDriveMedia = f
}

// UnMockDrivePartUploadDriveMedia un-mock DrivePartUploadDriveMedia method
func (r *Mock) UnMockDrivePartUploadDriveMedia() {
	r.mockDrivePartUploadDriveMedia = nil
}

// PartUploadDriveMediaReq ...
type PartUploadDriveMediaReq struct {
	UploadID string    `json:"upload_id,omitempty"` // 分片上传事务的 ID。通过调用[分片上传素材（预上传）](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/drive-v1/media/upload_prepare)接口获取, 示例值: "7111211691345512356"
	Seq      int64     `json:"seq,omitempty"`       // 块号, 从 0 开始计数, 示例值: 0
	Size     int64     `json:"size,omitempty"`      // 块的大小, 单位为字节, 示例值: 4194304
	Checksum *string   `json:"checksum,omitempty"`  // 素材文件的 Adler-32 校验和, 示例值: "3248270248"
	File     io.Reader `json:"file,omitempty"`      // 素材文件分片的二进制内容, 示例值: file binary
}

// PartUploadDriveMediaResp ...
type PartUploadDriveMediaResp struct {
}

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