// Package minutes code generated by oapi sdk gen
/*
 * MIT License
 *
 * Copyright (c) 2022 Lark Technologies Pte. Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package larkminutes

import (
	"io"

	"io/ioutil"

	"fmt"

	"github.com/larksuite/oapi-sdk-go/v3/core"
)

const (
	UserIdTypeUserId  = "user_id"  // 以user_id来识别用户
	UserIdTypeUnionId = "union_id" // 以union_id来识别用户
	UserIdTypeOpenId  = "open_id"  // 以open_id来识别用户
)

const (
	UserIdTypeGetMinuteStatisticsUserId  = "user_id"  // 以user_id来识别用户
	UserIdTypeGetMinuteStatisticsUnionId = "union_id" // 以union_id来识别用户
	UserIdTypeGetMinuteStatisticsOpenId  = "open_id"  // 以open_id来识别用户
)

type DepartmentId struct {
	DepartmentId *string `json:"department_id,omitempty"` //

	OpenDepartmentId *string `json:"open_department_id,omitempty"` //
}

type DepartmentIdBuilder struct {
	departmentId     string //
	departmentIdFlag bool

	openDepartmentId     string //
	openDepartmentIdFlag bool
}

func NewDepartmentIdBuilder() *DepartmentIdBuilder {
	builder := &DepartmentIdBuilder{}
	return builder
}

//
//
// 示例值：
func (builder *DepartmentIdBuilder) DepartmentId(departmentId string) *DepartmentIdBuilder {
	builder.departmentId = departmentId
	builder.departmentIdFlag = true
	return builder
}

//
//
// 示例值：
func (builder *DepartmentIdBuilder) OpenDepartmentId(openDepartmentId string) *DepartmentIdBuilder {
	builder.openDepartmentId = openDepartmentId
	builder.openDepartmentIdFlag = true
	return builder
}

func (builder *DepartmentIdBuilder) Build() *DepartmentId {
	req := &DepartmentId{}
	if builder.departmentIdFlag {
		req.DepartmentId = &builder.departmentId

	}
	if builder.openDepartmentIdFlag {
		req.OpenDepartmentId = &builder.openDepartmentId

	}
	return req
}

type Minute struct {
	Token *string `json:"token,omitempty"` // 妙记token

	OwnerId *string `json:"owner_id,omitempty"` // 所有者ID

	CreateTime *string `json:"create_time,omitempty"` // 妙记创建时间timestamp（ms级别）

	Title *string `json:"title,omitempty"` // 妙记标题

	Cover *string `json:"cover,omitempty"` // 妙记封面链接

	Duration *string `json:"duration,omitempty"` // 妙记时长（ms级别）

	Url *string `json:"url,omitempty"` // 妙记链接
}

type MinuteBuilder struct {
	token     string // 妙记token
	tokenFlag bool

	ownerId     string // 所有者ID
	ownerIdFlag bool

	createTime     string // 妙记创建时间timestamp（ms级别）
	createTimeFlag bool

	title     string // 妙记标题
	titleFlag bool

	cover     string // 妙记封面链接
	coverFlag bool

	duration     string // 妙记时长（ms级别）
	durationFlag bool

	url     string // 妙记链接
	urlFlag bool
}

func NewMinuteBuilder() *MinuteBuilder {
	builder := &MinuteBuilder{}
	return builder
}

// 妙记token
//
// 示例值：obcnq3b9jl72l83w4f149w9c
func (builder *MinuteBuilder) Token(token string) *MinuteBuilder {
	builder.token = token
	builder.tokenFlag = true
	return builder
}

// 所有者ID
//
// 示例值：ou_612b787ccd3259fb3c816b3f678d0426
func (builder *MinuteBuilder) OwnerId(ownerId string) *MinuteBuilder {
	builder.ownerId = ownerId
	builder.ownerIdFlag = true
	return builder
}

// 妙记创建时间timestamp（ms级别）
//
// 示例值：1669098360477
func (builder *MinuteBuilder) CreateTime(createTime string) *MinuteBuilder {
	builder.createTime = createTime
	builder.createTimeFlag = true
	return builder
}

// 妙记标题
//
// 示例值：xxx的视频会议
func (builder *MinuteBuilder) Title(title string) *MinuteBuilder {
	builder.title = title
	builder.titleFlag = true
	return builder
}

// 妙记封面链接
//
// 示例值：https://internal-api-drive-stream.feishu-pre.cn/space/api/box/stream/download/all/boxcncsI4EIhCSA1RLDsXDpCoQd
func (builder *MinuteBuilder) Cover(cover string) *MinuteBuilder {
	builder.cover = cover
	builder.coverFlag = true
	return builder
}

// 妙记时长（ms级别）
//
// 示例值：314000
func (builder *MinuteBuilder) Duration(duration string) *MinuteBuilder {
	builder.duration = duration
	builder.durationFlag = true
	return builder
}

// 妙记链接
//
// 示例值：https://bytedance.feishu-pre.cn/minutes/obcnq3b9jl72l83w4f149w9c
func (builder *MinuteBuilder) Url(url string) *MinuteBuilder {
	builder.url = url
	builder.urlFlag = true
	return builder
}

func (builder *MinuteBuilder) Build() *Minute {
	req := &Minute{}
	if builder.tokenFlag {
		req.Token = &builder.token

	}
	if builder.ownerIdFlag {
		req.OwnerId = &builder.ownerId

	}
	if builder.createTimeFlag {
		req.CreateTime = &builder.createTime

	}
	if builder.titleFlag {
		req.Title = &builder.title

	}
	if builder.coverFlag {
		req.Cover = &builder.cover

	}
	if builder.durationFlag {
		req.Duration = &builder.duration

	}
	if builder.urlFlag {
		req.Url = &builder.url

	}
	return req
}

type Statictics struct {
	UserViewCount *string `json:"user_view_count,omitempty"` // 用户浏览数

	PageViewCount *string `json:"page_view_count,omitempty"` // 页面浏览数量

	UserViewList []*UserViewDetail `json:"user_view_list,omitempty"` // 用户浏览列表
}

type StaticticsBuilder struct {
	userViewCount     string // 用户浏览数
	userViewCountFlag bool

	pageViewCount     string // 页面浏览数量
	pageViewCountFlag bool

	userViewList     []*UserViewDetail // 用户浏览列表
	userViewListFlag bool
}

func NewStaticticsBuilder() *StaticticsBuilder {
	builder := &StaticticsBuilder{}
	return builder
}

// 用户浏览数
//
// 示例值：3
func (builder *StaticticsBuilder) UserViewCount(userViewCount string) *StaticticsBuilder {
	builder.userViewCount = userViewCount
	builder.userViewCountFlag = true
	return builder
}

// 页面浏览数量
//
// 示例值：20
func (builder *StaticticsBuilder) PageViewCount(pageViewCount string) *StaticticsBuilder {
	builder.pageViewCount = pageViewCount
	builder.pageViewCountFlag = true
	return builder
}

// 用户浏览列表
//
// 示例值：
func (builder *StaticticsBuilder) UserViewList(userViewList []*UserViewDetail) *StaticticsBuilder {
	builder.userViewList = userViewList
	builder.userViewListFlag = true
	return builder
}

func (builder *StaticticsBuilder) Build() *Statictics {
	req := &Statictics{}
	if builder.userViewCountFlag {
		req.UserViewCount = &builder.userViewCount

	}
	if builder.pageViewCountFlag {
		req.PageViewCount = &builder.pageViewCount

	}
	if builder.userViewListFlag {
		req.UserViewList = builder.userViewList
	}
	return req
}

type UserViewDetail struct {
	UserId *string `json:"user_id,omitempty"` // 用户ID

	ViewTime *string `json:"view_time,omitempty"` // 用户的最近查看时间timestamp（ms级别）
}

type UserViewDetailBuilder struct {
	userId     string // 用户ID
	userIdFlag bool

	viewTime     string // 用户的最近查看时间timestamp（ms级别）
	viewTimeFlag bool
}

func NewUserViewDetailBuilder() *UserViewDetailBuilder {
	builder := &UserViewDetailBuilder{}
	return builder
}

// 用户ID
//
// 示例值：ou_612b787ccd3259fb3c816b3f678d0426
func (builder *UserViewDetailBuilder) UserId(userId string) *UserViewDetailBuilder {
	builder.userId = userId
	builder.userIdFlag = true
	return builder
}

// 用户的最近查看时间timestamp（ms级别）
//
// 示例值：1669121332000
func (builder *UserViewDetailBuilder) ViewTime(viewTime string) *UserViewDetailBuilder {
	builder.viewTime = viewTime
	builder.viewTimeFlag = true
	return builder
}

func (builder *UserViewDetailBuilder) Build() *UserViewDetail {
	req := &UserViewDetail{}
	if builder.userIdFlag {
		req.UserId = &builder.userId

	}
	if builder.viewTimeFlag {
		req.ViewTime = &builder.viewTime

	}
	return req
}

type GetMinuteReqBuilder struct {
	apiReq *larkcore.ApiReq
}

func NewGetMinuteReqBuilder() *GetMinuteReqBuilder {
	builder := &GetMinuteReqBuilder{}
	builder.apiReq = &larkcore.ApiReq{
		PathParams:  larkcore.PathParams{},
		QueryParams: larkcore.QueryParams{},
	}
	return builder
}

// 妙记的唯一标识
//
// 示例值：obcnq3b9jl72l83w4f149w9c
func (builder *GetMinuteReqBuilder) MinuteToken(minuteToken string) *GetMinuteReqBuilder {
	builder.apiReq.PathParams.Set("minute_token", fmt.Sprint(minuteToken))
	return builder
}

// 此次调用中使用的用户ID的类型
//
// 示例值：
func (builder *GetMinuteReqBuilder) UserIdType(userIdType string) *GetMinuteReqBuilder {
	builder.apiReq.QueryParams.Set("user_id_type", fmt.Sprint(userIdType))
	return builder
}

func (builder *GetMinuteReqBuilder) Build() *GetMinuteReq {
	req := &GetMinuteReq{}
	req.apiReq = &larkcore.ApiReq{}
	req.apiReq.PathParams = builder.apiReq.PathParams
	req.apiReq.QueryParams = builder.apiReq.QueryParams
	return req
}

type GetMinuteReq struct {
	apiReq *larkcore.ApiReq
}

type GetMinuteRespData struct {
	Minute *Minute `json:"minute,omitempty"` // 妙记基本信息
}

type GetMinuteResp struct {
	*larkcore.ApiResp `json:"-"`
	larkcore.CodeError
	Data *GetMinuteRespData `json:"data"` // 业务数据
}

func (resp *GetMinuteResp) Success() bool {
	return resp.Code == 0
}

type GetMinuteMediaReqBuilder struct {
	apiReq *larkcore.ApiReq
}

func NewGetMinuteMediaReqBuilder() *GetMinuteMediaReqBuilder {
	builder := &GetMinuteMediaReqBuilder{}
	builder.apiReq = &larkcore.ApiReq{
		PathParams:  larkcore.PathParams{},
		QueryParams: larkcore.QueryParams{},
	}
	return builder
}

// 妙记唯一标识
//
// 示例值：obcnq3b9jl72l83w4f149w9c
func (builder *GetMinuteMediaReqBuilder) MinuteToken(minuteToken string) *GetMinuteMediaReqBuilder {
	builder.apiReq.PathParams.Set("minute_token", fmt.Sprint(minuteToken))
	return builder
}

func (builder *GetMinuteMediaReqBuilder) Build() *GetMinuteMediaReq {
	req := &GetMinuteMediaReq{}
	req.apiReq = &larkcore.ApiReq{}
	req.apiReq.PathParams = builder.apiReq.PathParams
	return req
}

type GetMinuteMediaReq struct {
	apiReq *larkcore.ApiReq
}

type GetMinuteMediaRespData struct {
	DownloadUrl *string `json:"download_url,omitempty"` // 妙记音视频文件下载链接
}

type GetMinuteMediaResp struct {
	*larkcore.ApiResp `json:"-"`
	larkcore.CodeError
	Data *GetMinuteMediaRespData `json:"data"` // 业务数据
}

func (resp *GetMinuteMediaResp) Success() bool {
	return resp.Code == 0
}

type GetMinuteStatisticsReqBuilder struct {
	apiReq *larkcore.ApiReq
}

func NewGetMinuteStatisticsReqBuilder() *GetMinuteStatisticsReqBuilder {
	builder := &GetMinuteStatisticsReqBuilder{}
	builder.apiReq = &larkcore.ApiReq{
		PathParams:  larkcore.PathParams{},
		QueryParams: larkcore.QueryParams{},
	}
	return builder
}

// 妙记唯一标识
//
// 示例值：obcnq3b9jl72l83w4f149w9c
func (builder *GetMinuteStatisticsReqBuilder) MinuteToken(minuteToken string) *GetMinuteStatisticsReqBuilder {
	builder.apiReq.PathParams.Set("minute_token", fmt.Sprint(minuteToken))
	return builder
}

// 此次调用中使用的用户ID的类型
//
// 示例值：
func (builder *GetMinuteStatisticsReqBuilder) UserIdType(userIdType string) *GetMinuteStatisticsReqBuilder {
	builder.apiReq.QueryParams.Set("user_id_type", fmt.Sprint(userIdType))
	return builder
}

func (builder *GetMinuteStatisticsReqBuilder) Build() *GetMinuteStatisticsReq {
	req := &GetMinuteStatisticsReq{}
	req.apiReq = &larkcore.ApiReq{}
	req.apiReq.PathParams = builder.apiReq.PathParams
	req.apiReq.QueryParams = builder.apiReq.QueryParams
	return req
}

type GetMinuteStatisticsReq struct {
	apiReq *larkcore.ApiReq
}

type GetMinuteStatisticsRespData struct {
	Statistics *Statictics `json:"statistics,omitempty"` // 妙记浏览信息统计
}

type GetMinuteStatisticsResp struct {
	*larkcore.ApiResp `json:"-"`
	larkcore.CodeError
	Data *GetMinuteStatisticsRespData `json:"data"` // 业务数据
}

func (resp *GetMinuteStatisticsResp) Success() bool {
	return resp.Code == 0
}

type GetMinuteTranscriptReqBuilder struct {
	apiReq *larkcore.ApiReq
}

func NewGetMinuteTranscriptReqBuilder() *GetMinuteTranscriptReqBuilder {
	builder := &GetMinuteTranscriptReqBuilder{}
	builder.apiReq = &larkcore.ApiReq{
		PathParams:  larkcore.PathParams{},
		QueryParams: larkcore.QueryParams{},
	}
	return builder
}

// 妙记唯一标识
//
// 示例值：obcnq3b9jl72l83w4f149w9c
func (builder *GetMinuteTranscriptReqBuilder) MinuteToken(minuteToken string) *GetMinuteTranscriptReqBuilder {
	builder.apiReq.PathParams.Set("minute_token", fmt.Sprint(minuteToken))
	return builder
}

// 是否包含说话人
//
// 示例值：true
func (builder *GetMinuteTranscriptReqBuilder) NeedSpeaker(needSpeaker bool) *GetMinuteTranscriptReqBuilder {
	builder.apiReq.QueryParams.Set("need_speaker", fmt.Sprint(needSpeaker))
	return builder
}

// 是否包含时间戳
//
// 示例值：true
func (builder *GetMinuteTranscriptReqBuilder) NeedTimestamp(needTimestamp bool) *GetMinuteTranscriptReqBuilder {
	builder.apiReq.QueryParams.Set("need_timestamp", fmt.Sprint(needTimestamp))
	return builder
}

// 导出文件格式
//
// 示例值：txt；srt
func (builder *GetMinuteTranscriptReqBuilder) FileFormat(fileFormat string) *GetMinuteTranscriptReqBuilder {
	builder.apiReq.QueryParams.Set("file_format", fmt.Sprint(fileFormat))
	return builder
}

func (builder *GetMinuteTranscriptReqBuilder) Build() *GetMinuteTranscriptReq {
	req := &GetMinuteTranscriptReq{}
	req.apiReq = &larkcore.ApiReq{}
	req.apiReq.PathParams = builder.apiReq.PathParams
	req.apiReq.QueryParams = builder.apiReq.QueryParams
	return req
}

type GetMinuteTranscriptReq struct {
	apiReq *larkcore.ApiReq
}

type GetMinuteTranscriptResp struct {
	*larkcore.ApiResp `json:"-"`
	larkcore.CodeError
	File     io.Reader `json:"-"`
	FileName string    `json:"-"`
}

func (resp *GetMinuteTranscriptResp) Success() bool {
	return resp.Code == 0
}

func (resp *GetMinuteTranscriptResp) WriteFile(fileName string) error {
	bs, err := ioutil.ReadAll(resp.File)
	if err != nil {
		return err
	}

	err = ioutil.WriteFile(fileName, bs, 0666)
	if err != nil {
		return err
	}
	return nil
}
