// Code generated by Lark OpenAPI.

package larkminutes

import (
	"bytes"
	"context"
	"github.com/larksuite/oapi-sdk-go/v3/core"
	"net/http"
)

type V1 struct {
	Minute           *minute           // minute
	MinuteMedia      *minuteMedia      // minute.media
	MinuteStatistics *minuteStatistics // minute.statistics
	MinuteTranscript *minuteTranscript // minute.transcript
}

func New(config *larkcore.Config) *V1 {
	return &V1{
		Minute:           &minute{config: config},
		MinuteMedia:      &minuteMedia{config: config},
		MinuteStatistics: &minuteStatistics{config: config},
		MinuteTranscript: &minuteTranscript{config: config},
	}
}

type minute struct {
	config *larkcore.Config
}
type minuteMedia struct {
	config *larkcore.Config
}
type minuteStatistics struct {
	config *larkcore.Config
}
type minuteTranscript struct {
	config *larkcore.Config
}

// Get
//
// - 获取妙记的基础概括信息
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=get&project=minutes&resource=minute&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/minutesv1/get_minute.go
func (m *minute) Get(ctx context.Context, req *GetMinuteReq, options ...larkcore.RequestOptionFunc) (*GetMinuteResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/minutes/v1/minutes/:minute_token"
	apiReq.HttpMethod = http.MethodGet
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, m.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &GetMinuteResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, m.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Get
//
// - 获取妙记的音视频文件
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=get&project=minutes&resource=minute.media&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/minutesv1/get_minuteMedia.go
func (m *minuteMedia) Get(ctx context.Context, req *GetMinuteMediaReq, options ...larkcore.RequestOptionFunc) (*GetMinuteMediaResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/minutes/v1/minutes/:minute_token/media"
	apiReq.HttpMethod = http.MethodGet
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, m.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &GetMinuteMediaResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, m.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Get
//
// - 获取妙记的访问统计数据
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=get&project=minutes&resource=minute.statistics&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/minutesv1/get_minuteStatistics.go
func (m *minuteStatistics) Get(ctx context.Context, req *GetMinuteStatisticsReq, options ...larkcore.RequestOptionFunc) (*GetMinuteStatisticsResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/minutes/v1/minutes/:minute_token/statistics"
	apiReq.HttpMethod = http.MethodGet
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, m.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &GetMinuteStatisticsResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, m.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Get
//
// - 获取妙记的对话文本，成功时返回文件二进制流
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=get&project=minutes&resource=minute.transcript&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/minutesv1/get_minuteTranscript.go
func (m *minuteTranscript) Get(ctx context.Context, req *GetMinuteTranscriptReq, options ...larkcore.RequestOptionFunc) (*GetMinuteTranscriptResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/minutes/v1/minutes/:minute_token/transcript"
	apiReq.HttpMethod = http.MethodGet
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, m.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &GetMinuteTranscriptResp{ApiResp: apiResp}
	// 如果是下载，则设置响应结果
	if apiResp.StatusCode == http.StatusOK {
		resp.File = bytes.NewBuffer(apiResp.RawBody)
		resp.FileName = larkcore.FileNameByHeader(apiResp.Header)
		return resp, err
	}
	err = apiResp.JSONUnmarshalBody(resp, m.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}
