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

// IsInChat 根据使用的access_token判断对应的用户或者机器人是否在群里。
//
// 注意事项:
// - 应用需要开启[机器人能力](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)
// - 获取内部群信息时, 操作者须与群组在同一租户下
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-members/is_in_chat
// new doc: https://open.feishu.cn/document/server-docs/group/chat-member/is_in_chat
func (r *ChatService) IsInChat(ctx context.Context, request *IsInChatReq, options ...MethodOptionFunc) (*IsInChatResp, *Response, error) {
	if r.cli.mock.mockChatIsInChat != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Chat#IsInChat mock enable")
		return r.cli.mock.mockChatIsInChat(ctx, request, options...)
	}

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

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

// MockChatIsInChat mock ChatIsInChat method
func (r *Mock) MockChatIsInChat(f func(ctx context.Context, request *IsInChatReq, options ...MethodOptionFunc) (*IsInChatResp, *Response, error)) {
	r.mockChatIsInChat = f
}

// UnMockChatIsInChat un-mock ChatIsInChat method
func (r *Mock) UnMockChatIsInChat() {
	r.mockChatIsInChat = nil
}

// IsInChatReq ...
type IsInChatReq struct {
	ChatID string `path:"chat_id" json:"-"` // 群 ID, 详情参见[群ID 说明](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-id-description), 示例值: "oc_a0553eda9014c201e6969b478895c230"
}

// IsInChatResp ...
type IsInChatResp struct {
	IsInChat bool `json:"is_in_chat,omitempty"` // 用户或者机器人是否在群中
}

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