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

// CheckApprovalExternalInstance 校验三方审批实例数据, 用于判断服务端数据是否为最新的。用户提交实例最新更新时间, 如果服务端不存在该实例, 或者服务端实例更新时间不是最新的, 则返回对应实例 id。
//
// 例如, 用户可以每隔5分钟, 将最近5分钟产生的实例使用该接口进行对比。
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/approval-v4/external_instance/check
// new doc: https://open.feishu.cn/document/server-docs/approval-v4/external_instance/check
func (r *ApprovalService) CheckApprovalExternalInstance(ctx context.Context, request *CheckApprovalExternalInstanceReq, options ...MethodOptionFunc) (*CheckApprovalExternalInstanceResp, *Response, error) {
	if r.cli.mock.mockApprovalCheckApprovalExternalInstance != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Approval#CheckApprovalExternalInstance mock enable")
		return r.cli.mock.mockApprovalCheckApprovalExternalInstance(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "Approval",
		API:                   "CheckApprovalExternalInstance",
		Method:                "POST",
		URL:                   r.cli.openBaseURL + "/open-apis/approval/v4/external_instances/check",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
	}
	resp := new(checkApprovalExternalInstanceResp)

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

// MockApprovalCheckApprovalExternalInstance mock ApprovalCheckApprovalExternalInstance method
func (r *Mock) MockApprovalCheckApprovalExternalInstance(f func(ctx context.Context, request *CheckApprovalExternalInstanceReq, options ...MethodOptionFunc) (*CheckApprovalExternalInstanceResp, *Response, error)) {
	r.mockApprovalCheckApprovalExternalInstance = f
}

// UnMockApprovalCheckApprovalExternalInstance un-mock ApprovalCheckApprovalExternalInstance method
func (r *Mock) UnMockApprovalCheckApprovalExternalInstance() {
	r.mockApprovalCheckApprovalExternalInstance = nil
}

// CheckApprovalExternalInstanceReq ...
type CheckApprovalExternalInstanceReq struct {
	Instances []*CheckApprovalExternalInstanceReqInstance `json:"instances,omitempty"` // 校验的实例信息
}

// CheckApprovalExternalInstanceReqInstance ...
type CheckApprovalExternalInstanceReqInstance struct {
	InstanceID string                                          `json:"instance_id,omitempty"` // 审批实例 id, 示例值: "1234234234242423"
	UpdateTime string                                          `json:"update_time,omitempty"` // 审批实例最近更新时间, 示例值: "1591603040000"
	Tasks      []*CheckApprovalExternalInstanceReqInstanceTask `json:"tasks,omitempty"`       // 任务信息
}

// CheckApprovalExternalInstanceReqInstanceTask ...
type CheckApprovalExternalInstanceReqInstanceTask struct {
	TaskID     string `json:"task_id,omitempty"`     // 任务 id, 示例值: "112253"
	UpdateTime string `json:"update_time,omitempty"` // 任务最近更新时间, 示例值: "1591603040000"
}

// CheckApprovalExternalInstanceResp ...
type CheckApprovalExternalInstanceResp struct {
	DiffInstances []*CheckApprovalExternalInstanceRespDiffInstance `json:"diff_instances,omitempty"` // 更新时间不一致的实例信息
}

// CheckApprovalExternalInstanceRespDiffInstance ...
type CheckApprovalExternalInstanceRespDiffInstance struct {
	InstanceID string                                               `json:"instance_id,omitempty"` // 审批实例 id
	UpdateTime string                                               `json:"update_time,omitempty"` // 任务最近更新时间
	Tasks      []*CheckApprovalExternalInstanceRespDiffInstanceTask `json:"tasks,omitempty"`       // 任务信息
}

// CheckApprovalExternalInstanceRespDiffInstanceTask ...
type CheckApprovalExternalInstanceRespDiffInstanceTask struct {
	TaskID     string `json:"task_id,omitempty"`     // 任务 id
	UpdateTime string `json:"update_time,omitempty"` // 任务最近更新时间
}

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