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

// AddTaskCustomField 将自定义字段加入一个资源。目前资源类型支持清单tasklist。一个自定义字段可以加入多个清单中。加入后, 该清单可以展示任务的该字段的值, 同时基于该字段实现筛选, 分组等功能。
//
// 如果自定义字段的设置被更新, 字段加入的所有字段都能收到这个更新, 并进行相应的展示。
// 将自定义字段加入一个资源需要该字段和资源的可编辑权限。
//
// doc: https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/task-v2/custom_field/add
func (r *TaskService) AddTaskCustomField(ctx context.Context, request *AddTaskCustomFieldReq, options ...MethodOptionFunc) (*AddTaskCustomFieldResp, *Response, error) {
	if r.cli.mock.mockTaskAddTaskCustomField != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Task#AddTaskCustomField mock enable")
		return r.cli.mock.mockTaskAddTaskCustomField(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "Task",
		API:                   "AddTaskCustomField",
		Method:                "POST",
		URL:                   r.cli.openBaseURL + "/open-apis/task/v2/custom_fields/:custom_field_guid/add",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
		NeedUserAccessToken:   true,
	}
	resp := new(addTaskCustomFieldResp)

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

// MockTaskAddTaskCustomField mock TaskAddTaskCustomField method
func (r *Mock) MockTaskAddTaskCustomField(f func(ctx context.Context, request *AddTaskCustomFieldReq, options ...MethodOptionFunc) (*AddTaskCustomFieldResp, *Response, error)) {
	r.mockTaskAddTaskCustomField = f
}

// UnMockTaskAddTaskCustomField un-mock TaskAddTaskCustomField method
func (r *Mock) UnMockTaskAddTaskCustomField() {
	r.mockTaskAddTaskCustomField = nil
}

// AddTaskCustomFieldReq ...
type AddTaskCustomFieldReq struct {
	CustomFieldGuid string `path:"custom_field_guid" json:"-"` // 自定义字段GUID。自定义字段GUID。可以通过[创建自定义字段](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/custom_field/create)接口创建, 或者通过[列取自定义字段](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/task-v2/custom_field/list)接口查询得到, 示例值: "0110a4bd-f24b-4a93-8c1a-1732b94f9593"
	ResourceType    string `json:"resource_type,omitempty"`    // 要将自定义字段添加到一个资源的资源类型。目前只支持tasklist, 示例值: "tasklist"
	ResourceID      string `json:"resource_id,omitempty"`      // 要将自定义字段添加到的资源id, 目前只支持tasklist_guid, 示例值: "0110a4bd-f24b-4a93-8c1a-1732b94f9593"
}

// AddTaskCustomFieldResp ...
type AddTaskCustomFieldResp struct {
}

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