// Code generated by Lark OpenAPI.

package larkboard

import (
	"bytes"
	"context"
	"github.com/larksuite/oapi-sdk-go/v3/core"
	"net/http"
)

type V1 struct {
	Whiteboard     *whiteboard     // whiteboard
	WhiteboardNode *whiteboardNode // whiteboard.node
}

func New(config *larkcore.Config) *V1 {
	return &V1{
		Whiteboard:     &whiteboard{config: config},
		WhiteboardNode: &whiteboardNode{config: config},
	}
}

type whiteboard struct {
	config *larkcore.Config
}
type whiteboardNode struct {
	config *larkcore.Config
}

// DownloadAsImage
//
// - 下载画板为图片
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=download_as_image&project=board&resource=whiteboard&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/boardv1/downloadAsImage_whiteboard.go
func (w *whiteboard) DownloadAsImage(ctx context.Context, req *DownloadAsImageWhiteboardReq, options ...larkcore.RequestOptionFunc) (*DownloadAsImageWhiteboardResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/board/v1/whiteboards/:whiteboard_id/download_as_image"
	apiReq.HttpMethod = http.MethodGet
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, w.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &DownloadAsImageWhiteboardResp{ApiResp: apiResp}
	// 如果是下载，则设置响应结果
	if apiResp.StatusCode == http.StatusOK {
		resp.File = bytes.NewBuffer(apiResp.RawBody)
		resp.FileName = larkcore.FileNameByHeader(apiResp.Header)
		return resp, err
	}
	err = apiResp.JSONUnmarshalBody(resp, w.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Theme
//
// - 获取画板的主题
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=theme&project=board&resource=whiteboard&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/boardv1/theme_whiteboard.go
func (w *whiteboard) Theme(ctx context.Context, req *ThemeWhiteboardReq, options ...larkcore.RequestOptionFunc) (*ThemeWhiteboardResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/board/v1/whiteboards/:whiteboard_id/theme"
	apiReq.HttpMethod = http.MethodGet
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant}
	apiResp, err := larkcore.Request(ctx, apiReq, w.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &ThemeWhiteboardResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, w.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// UpdateTheme
//
// - 更新画板主题
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=update_theme&project=board&resource=whiteboard&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/boardv1/updateTheme_whiteboard.go
func (w *whiteboard) UpdateTheme(ctx context.Context, req *UpdateThemeWhiteboardReq, options ...larkcore.RequestOptionFunc) (*UpdateThemeWhiteboardResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/board/v1/whiteboards/:whiteboard_id/update_theme"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant}
	apiResp, err := larkcore.Request(ctx, apiReq, w.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &UpdateThemeWhiteboardResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, w.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Create
//
// - 在画板中创建节点
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=create&project=board&resource=whiteboard.node&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/boardv1/create_whiteboardNode.go
func (w *whiteboardNode) Create(ctx context.Context, req *CreateWhiteboardNodeReq, options ...larkcore.RequestOptionFunc) (*CreateWhiteboardNodeResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/board/v1/whiteboards/:whiteboard_id/nodes"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, w.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &CreateWhiteboardNodeResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, w.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// CreatePlantuml
//
// - 创建 plant uml 图形
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=create_plantuml&project=board&resource=whiteboard.node&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/boardv1/createPlantuml_whiteboardNode.go
func (w *whiteboardNode) CreatePlantuml(ctx context.Context, req *CreatePlantumlWhiteboardNodeReq, options ...larkcore.RequestOptionFunc) (*CreatePlantumlWhiteboardNodeResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/board/v1/whiteboards/:whiteboard_id/nodes/plantuml"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser, larkcore.AccessTokenTypeTenant}
	apiResp, err := larkcore.Request(ctx, apiReq, w.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &CreatePlantumlWhiteboardNodeResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, w.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// List
//
// - 列出画板内的节点数据
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=list&project=board&resource=whiteboard.node&version=v1
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/boardv1/list_whiteboardNode.go
func (w *whiteboardNode) List(ctx context.Context, req *ListWhiteboardNodeReq, options ...larkcore.RequestOptionFunc) (*ListWhiteboardNodeResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/board/v1/whiteboards/:whiteboard_id/nodes"
	apiReq.HttpMethod = http.MethodGet
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant, larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, w.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &ListWhiteboardNodeResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, w.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}
