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

// UploadFile 上传文件, 可以上传视频, 音频和常见的文件类型。
//
// 注意事项:
// - 需要开启[机器人能力](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)
// - 文件大小不得超过30M, 且不允许上传空文件
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/file/create
// new doc: https://open.feishu.cn/document/server-docs/im-v1/file/create
func (r *FileService) UploadFile(ctx context.Context, request *UploadFileReq, options ...MethodOptionFunc) (*UploadFileResp, *Response, error) {
	if r.cli.mock.mockFileUploadFile != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] File#UploadFile mock enable")
		return r.cli.mock.mockFileUploadFile(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "File",
		API:                   "UploadFile",
		Method:                "POST",
		URL:                   r.cli.openBaseURL + "/open-apis/im/v1/files",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
		IsFile:                true,
	}
	resp := new(uploadFileResp)

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

// MockFileUploadFile mock FileUploadFile method
func (r *Mock) MockFileUploadFile(f func(ctx context.Context, request *UploadFileReq, options ...MethodOptionFunc) (*UploadFileResp, *Response, error)) {
	r.mockFileUploadFile = f
}

// UnMockFileUploadFile un-mock FileUploadFile method
func (r *Mock) UnMockFileUploadFile() {
	r.mockFileUploadFile = nil
}

// UploadFileReq ...
type UploadFileReq struct {
	FileType FileType  `json:"file_type,omitempty"` // 文件类型, 示例值: "mp4", 可选值有: opus: 上传opus音频文件；, 其他格式的音频文件, 请转为opus格式后上传, 转换方式可参考: `ffmpeg -i  SourceFile.mp3 -acodec libopus -ac 1 -ar 16000 TargetFile.opus`, mp4: 上传mp4视频文件, pdf: 上传pdf格式文件, doc: 上传doc格式文件, xls: 上传xls格式文件, ppt: 上传ppt格式文件, stream: 上传stream格式文件。若上传文件不属于以上类型, 可以使用stream格式
	FileName string    `json:"file_name,omitempty"` // 带后缀的文件名, 示例值: "测试视频.mp4"
	Duration *int64    `json:"duration,omitempty"`  // 文件的时长（视频、音频）, 单位:毫秒。不填充时无法显示具体时长, 示例值: 3000
	File     io.Reader `json:"file,omitempty"`      // 文件内容, 示例值: 二进制文件
}

// UploadFileResp ...
type UploadFileResp struct {
	FileKey string `json:"file_key,omitempty"` // 文件的key
}

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