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

// GenChatShareLink 获取指定群的分享链接。
//
// 注意事项:
// - 应用需要开启[机器人能力](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)
// - access_token所对应的 机器人 或 授权用户 必须在`chat_id`参数指定的群组中
// - 单聊、密聊、团队群不支持分享群链接
// - 当Bot被停用或Bot退出群组时, Bot生成的群链接也将停用
// - 当群聊开启了 [仅群主和群管理员可添加群成员/分享群] 设置时, 仅群主和群管理员可以获取群分享链接
// - 获取内部群分享链接时, 操作者须与群组在同一租户下
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/link
// new doc: https://open.feishu.cn/document/server-docs/group/chat/link
func (r *ChatService) GenChatShareLink(ctx context.Context, request *GenChatShareLinkReq, options ...MethodOptionFunc) (*GenChatShareLinkResp, *Response, error) {
	if r.cli.mock.mockChatGenChatShareLink != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Chat#GenChatShareLink mock enable")
		return r.cli.mock.mockChatGenChatShareLink(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "Chat",
		API:                   "GenChatShareLink",
		Method:                "POST",
		URL:                   r.cli.openBaseURL + "/open-apis/im/v1/chats/:chat_id/link",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
		NeedUserAccessToken:   true,
	}
	resp := new(genChatShareLinkResp)

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

// MockChatGenChatShareLink mock ChatGenChatShareLink method
func (r *Mock) MockChatGenChatShareLink(f func(ctx context.Context, request *GenChatShareLinkReq, options ...MethodOptionFunc) (*GenChatShareLinkResp, *Response, error)) {
	r.mockChatGenChatShareLink = f
}

// UnMockChatGenChatShareLink un-mock ChatGenChatShareLink method
func (r *Mock) UnMockChatGenChatShareLink() {
	r.mockChatGenChatShareLink = nil
}

// GenChatShareLinkReq ...
type GenChatShareLinkReq struct {
	ChatID         string  `path:"chat_id" json:"-"`          // 待获取分享链接的群ID, 详情参见[群ID 说明](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-id-description), 注意: 单聊、密聊、团队群不支持分享群链接, 示例值: "oc_a0553eda9014c201e6969b478895c230"
	ValidityPeriod *string `json:"validity_period,omitempty"` // 群分享链接有效时长, 可选值week、year、permanently, 分别表示7天、1年以及永久有效, 示例值: "week", 可选值有: week: 有效期7天, year: 有效期1年, permanently: 永久有效, 默认值: `week`
}

// GenChatShareLinkResp ...
type GenChatShareLinkResp struct {
	ShareLink   string `json:"share_link,omitempty"`   // 群分享链接
	ExpireTime  string `json:"expire_time,omitempty"`  // 分享链接过期时间戳（秒级）
	IsPermanent bool   `json:"is_permanent,omitempty"` // 分享链接是否永久有效
}

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