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

// DownloadImage 下载图片资源, 只能下载当前应用所上传且图片类型为message的图片。
//
// 注意事项:
// - 需要开启[机器人能力](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)
// - 只能下载机器人自己上传且图片类型为message的图片, avatar类型暂不支持下载
// - 下载用户发送的资源, 请使用[获取消息中的资源文件](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/message-resource/get)接口
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/get
// new doc: https://open.feishu.cn/document/server-docs/im-v1/image/get
func (r *FileService) DownloadImage(ctx context.Context, request *DownloadImageReq, options ...MethodOptionFunc) (*DownloadImageResp, *Response, error) {
	if r.cli.mock.mockFileDownloadImage != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] File#DownloadImage mock enable")
		return r.cli.mock.mockFileDownloadImage(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "File",
		API:                   "DownloadImage",
		Method:                "GET",
		URL:                   r.cli.openBaseURL + "/open-apis/im/v1/images/:image_key",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
	}
	resp := new(downloadImageResp)

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

// MockFileDownloadImage mock FileDownloadImage method
func (r *Mock) MockFileDownloadImage(f func(ctx context.Context, request *DownloadImageReq, options ...MethodOptionFunc) (*DownloadImageResp, *Response, error)) {
	r.mockFileDownloadImage = f
}

// UnMockFileDownloadImage un-mock FileDownloadImage method
func (r *Mock) UnMockFileDownloadImage() {
	r.mockFileDownloadImage = nil
}

// DownloadImageReq ...
type DownloadImageReq struct {
	ImageKey string `path:"image_key" json:"-"` // 图片的key, 通过[上传图片](	/ssl:ttdoc/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create)接口上传图片后获得, 示例值: "img_8d5181ca-0aed-40f0-b0d1-b1452132afbg"
}

// downloadImageResp ...
type downloadImageResp struct {
	Code  int64              `json:"code,omitempty"`
	Msg   string             `json:"msg,omitempty"`
	Data  *DownloadImageResp `json:"data,omitempty"`
	Error *ErrorDetail       `json:"error,omitempty"`
}

func (r *downloadImageResp) SetReader(file io.Reader) {
	if r.Data == nil {
		r.Data = &DownloadImageResp{}
	}
	r.Data.File = file
}

// DownloadImageResp ...
type DownloadImageResp struct {
	File io.Reader `json:"file,omitempty"`
}
