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

// UpdateBitableMeta 通过 app_token 更新多维表格元数据
//
// - 飞书文档、飞书表格、知识库中的多维表格不支持开启高级权限
// - 此接口非原子操作, 先修改多维表格名字, 后开关高级权限。可能存在部分成功的情况
//
// doc: https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/bitable-v1/app/update
// new doc: https://open.feishu.cn/document/server-docs/docs/bitable-v1/app/update
func (r *BitableService) UpdateBitableMeta(ctx context.Context, request *UpdateBitableMetaReq, options ...MethodOptionFunc) (*UpdateBitableMetaResp, *Response, error) {
	if r.cli.mock.mockBitableUpdateBitableMeta != nil {
		r.cli.Log(ctx, LogLevelDebug, "[lark] Bitable#UpdateBitableMeta mock enable")
		return r.cli.mock.mockBitableUpdateBitableMeta(ctx, request, options...)
	}

	req := &RawRequestReq{
		Scope:                 "Bitable",
		API:                   "UpdateBitableMeta",
		Method:                "PUT",
		URL:                   r.cli.openBaseURL + "/open-apis/bitable/v1/apps/:app_token",
		Body:                  request,
		MethodOption:          newMethodOption(options),
		NeedTenantAccessToken: true,
		NeedUserAccessToken:   true,
	}
	resp := new(updateBitableMetaResp)

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

// MockBitableUpdateBitableMeta mock BitableUpdateBitableMeta method
func (r *Mock) MockBitableUpdateBitableMeta(f func(ctx context.Context, request *UpdateBitableMetaReq, options ...MethodOptionFunc) (*UpdateBitableMetaResp, *Response, error)) {
	r.mockBitableUpdateBitableMeta = f
}

// UnMockBitableUpdateBitableMeta un-mock BitableUpdateBitableMeta method
func (r *Mock) UnMockBitableUpdateBitableMeta() {
	r.mockBitableUpdateBitableMeta = nil
}

// UpdateBitableMetaReq ...
type UpdateBitableMetaReq struct {
	AppToken   string  `path:"app_token" json:"-"`    // Base app token, 示例值: "appbcbWCzen6D8dezhoCH2RpMAh"
	Name       *string `json:"name,omitempty"`        // 新的多维表格名字, 示例值: "新的多维表格名字"
	IsAdvanced *bool   `json:"is_advanced,omitempty"` // 多维表格是否开启高级权限, 示例值: true
}

// UpdateBitableMetaResp ...
type UpdateBitableMetaResp struct {
	App *UpdateBitableMetaRespApp `json:"app,omitempty"` // 多维表格元数据
}

// UpdateBitableMetaRespApp ...
type UpdateBitableMetaRespApp struct {
	AppToken   string `json:"app_token,omitempty"`   // 多维表格的 app_token
	Name       string `json:"name,omitempty"`        // 多维表格的名字
	IsAdvanced bool   `json:"is_advanced,omitempty"` // 多维表格是否已开启高级权限
	TimeZone   string `json:"time_zone,omitempty"`   // 文档时区
}

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