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

// AddTaskDependency 为一个任务添加一个或多个依赖。可以添加任务的前置依赖和后置依赖。存在依赖关系的任务如果在同一个清单, 可以通过清单的甘特图来展示其依赖关系。
//
// 本接口也可以用于修改一个现有依赖的类型（前置改为后置或者后置改为前置）。
// 注意: 添加的依赖的`task_guid`不能重复, 也不能添加当前任务为自己的依赖。尝试添加一个已经存在的依赖会被自动忽略。
// 添加任务依赖需要调用身份拥有当前任务的编辑权限和所有被添加为依赖的任务的编辑权限。
//
// doc: https://open.larkoffice.com/document/uAjLw4CM/ukTMukTMukTM/task-v2/task/add_dependencies
func (r *TaskService) AddTaskDependency(ctx context.Context, request *AddTaskDependencyReq, options ...MethodOptionFunc) (*AddTaskDependencyResp, *Response, error) {
	if r.cli.mock.mockTaskAddTaskDependency != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Task#AddTaskDependency mock enable")
		return r.cli.mock.mockTaskAddTaskDependency(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "Task",
		API:                   "AddTaskDependency",
		Method:                "POST",
		URL:                   r.cli.openBaseURL + "/open-apis/task/v2/tasks/:task_guid/add_dependencies",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
		NeedUserAccessToken:   true,
	}
	resp := new(addTaskDependencyResp)

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

// MockTaskAddTaskDependency mock TaskAddTaskDependency method
func (r *Mock) MockTaskAddTaskDependency(f func(ctx context.Context, request *AddTaskDependencyReq, options ...MethodOptionFunc) (*AddTaskDependencyResp, *Response, error)) {
	r.mockTaskAddTaskDependency = f
}

// UnMockTaskAddTaskDependency un-mock TaskAddTaskDependency method
func (r *Mock) UnMockTaskAddTaskDependency() {
	r.mockTaskAddTaskDependency = nil
}

// AddTaskDependencyReq ...
type AddTaskDependencyReq struct {
	TaskGuid     string                             `path:"task_guid" json:"-"`     // 任务GUID, 示例值: "93b7bd05-35e6-4371-b3c9-6b7cbd7100c0"
	Dependencies []*AddTaskDependencyReqDependencie `json:"dependencies,omitempty"` // 要添加的依赖, 长度范围: `1` ～ `50`
}

// AddTaskDependencyReqDependencie ...
type AddTaskDependencyReqDependencie struct {
	Type     string `json:"type,omitempty"`      // 依赖类型, 示例值: "next", 可选值有: prev: 前置依赖, next: 后置依赖
	TaskGuid string `json:"task_guid,omitempty"` // 依赖任务的GUID, 示例值: "93b7bd05-35e6-4371-b3c9-6b7cbd7100c0"
}

// AddTaskDependencyResp ...
type AddTaskDependencyResp struct {
	Dependencies []*AddTaskDependencyRespDependencie `json:"dependencies,omitempty"` // 被添加后任务的所有依赖
}

// AddTaskDependencyRespDependencie ...
type AddTaskDependencyRespDependencie struct {
	Type     string `json:"type,omitempty"`      // 依赖类型, 可选值有: prev: 前置依赖, next: 后置依赖
	TaskGuid string `json:"task_guid,omitempty"` // 依赖任务的GUID
}

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