// Package wiki code generated by oapi sdk gen
/*
 * MIT License
 *
 * Copyright (c) 2022 Lark Technologies Pte. Ltd.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package larkwiki

import (
	"fmt"

	"context"
	"errors"

	"github.com/larksuite/oapi-sdk-go/v3/core"
)

type DepartmentId struct {
	DepartmentId *string `json:"department_id,omitempty"` //

	OpenDepartmentId *string `json:"open_department_id,omitempty"` //
}

type DepartmentIdBuilder struct {
	departmentId     string //
	departmentIdFlag bool

	openDepartmentId     string //
	openDepartmentIdFlag bool
}

func NewDepartmentIdBuilder() *DepartmentIdBuilder {
	builder := &DepartmentIdBuilder{}
	return builder
}

//
//
// 示例值：
func (builder *DepartmentIdBuilder) DepartmentId(departmentId string) *DepartmentIdBuilder {
	builder.departmentId = departmentId
	builder.departmentIdFlag = true
	return builder
}

//
//
// 示例值：
func (builder *DepartmentIdBuilder) OpenDepartmentId(openDepartmentId string) *DepartmentIdBuilder {
	builder.openDepartmentId = openDepartmentId
	builder.openDepartmentIdFlag = true
	return builder
}

func (builder *DepartmentIdBuilder) Build() *DepartmentId {
	req := &DepartmentId{}
	if builder.departmentIdFlag {
		req.DepartmentId = &builder.departmentId

	}
	if builder.openDepartmentIdFlag {
		req.OpenDepartmentId = &builder.openDepartmentId

	}
	return req
}

type Node struct {
	NodeId *string `json:"node_id,omitempty"` // node的唯一标识

	SpaceId *string `json:"space_id,omitempty"` // 所属空间id

	ParentId *string `json:"parent_id,omitempty"` // 父节点id

	ObjType *int `json:"obj_type,omitempty"` // 对应的obj类型

	Title *string `json:"title,omitempty"` // 名称

	Url *string `json:"url,omitempty"` // 路径

	Icon *string `json:"icon,omitempty"` // icon

	AreaId *string `json:"area_id,omitempty"` // 所属权限范围id

	SortId *float64 `json:"sort_id,omitempty"` // 序号

	Domain *string `json:"domain,omitempty"` // 所在域名

	ObjToken *string `json:"obj_token,omitempty"` // objToken

	CreateTime *string `json:"create_time,omitempty"` // 创建时间

	UpdateTime *string `json:"update_time,omitempty"` // 更新时间

	DeleteTime *string `json:"delete_time,omitempty"` // 删除时间

	ChildNum *int `json:"child_num,omitempty"` // 子节点数

	Version *int `json:"version,omitempty"` // 版本号
}

type NodeBuilder struct {
	nodeId     string // node的唯一标识
	nodeIdFlag bool

	spaceId     string // 所属空间id
	spaceIdFlag bool

	parentId     string // 父节点id
	parentIdFlag bool

	objType     int // 对应的obj类型
	objTypeFlag bool

	title     string // 名称
	titleFlag bool

	url     string // 路径
	urlFlag bool

	icon     string // icon
	iconFlag bool

	areaId     string // 所属权限范围id
	areaIdFlag bool

	sortId     float64 // 序号
	sortIdFlag bool

	domain     string // 所在域名
	domainFlag bool

	objToken     string // objToken
	objTokenFlag bool

	createTime     string // 创建时间
	createTimeFlag bool

	updateTime     string // 更新时间
	updateTimeFlag bool

	deleteTime     string // 删除时间
	deleteTimeFlag bool

	childNum     int // 子节点数
	childNumFlag bool

	version     int // 版本号
	versionFlag bool
}

func NewNodeBuilder() *NodeBuilder {
	builder := &NodeBuilder{}
	return builder
}

// node的唯一标识
//
// 示例值：
func (builder *NodeBuilder) NodeId(nodeId string) *NodeBuilder {
	builder.nodeId = nodeId
	builder.nodeIdFlag = true
	return builder
}

// 所属空间id
//
// 示例值：
func (builder *NodeBuilder) SpaceId(spaceId string) *NodeBuilder {
	builder.spaceId = spaceId
	builder.spaceIdFlag = true
	return builder
}

// 父节点id
//
// 示例值：
func (builder *NodeBuilder) ParentId(parentId string) *NodeBuilder {
	builder.parentId = parentId
	builder.parentIdFlag = true
	return builder
}

// 对应的obj类型
//
// 示例值：
func (builder *NodeBuilder) ObjType(objType int) *NodeBuilder {
	builder.objType = objType
	builder.objTypeFlag = true
	return builder
}

// 名称
//
// 示例值：
func (builder *NodeBuilder) Title(title string) *NodeBuilder {
	builder.title = title
	builder.titleFlag = true
	return builder
}

// 路径
//
// 示例值：
func (builder *NodeBuilder) Url(url string) *NodeBuilder {
	builder.url = url
	builder.urlFlag = true
	return builder
}

// icon
//
// 示例值：
func (builder *NodeBuilder) Icon(icon string) *NodeBuilder {
	builder.icon = icon
	builder.iconFlag = true
	return builder
}

// 所属权限范围id
//
// 示例值：
func (builder *NodeBuilder) AreaId(areaId string) *NodeBuilder {
	builder.areaId = areaId
	builder.areaIdFlag = true
	return builder
}

// 序号
//
// 示例值：
func (builder *NodeBuilder) SortId(sortId float64) *NodeBuilder {
	builder.sortId = sortId
	builder.sortIdFlag = true
	return builder
}

// 所在域名
//
// 示例值：
func (builder *NodeBuilder) Domain(domain string) *NodeBuilder {
	builder.domain = domain
	builder.domainFlag = true
	return builder
}

// objToken
//
// 示例值：
func (builder *NodeBuilder) ObjToken(objToken string) *NodeBuilder {
	builder.objToken = objToken
	builder.objTokenFlag = true
	return builder
}

// 创建时间
//
// 示例值：
func (builder *NodeBuilder) CreateTime(createTime string) *NodeBuilder {
	builder.createTime = createTime
	builder.createTimeFlag = true
	return builder
}

// 更新时间
//
// 示例值：
func (builder *NodeBuilder) UpdateTime(updateTime string) *NodeBuilder {
	builder.updateTime = updateTime
	builder.updateTimeFlag = true
	return builder
}

// 删除时间
//
// 示例值：
func (builder *NodeBuilder) DeleteTime(deleteTime string) *NodeBuilder {
	builder.deleteTime = deleteTime
	builder.deleteTimeFlag = true
	return builder
}

// 子节点数
//
// 示例值：
func (builder *NodeBuilder) ChildNum(childNum int) *NodeBuilder {
	builder.childNum = childNum
	builder.childNumFlag = true
	return builder
}

// 版本号
//
// 示例值：
func (builder *NodeBuilder) Version(version int) *NodeBuilder {
	builder.version = version
	builder.versionFlag = true
	return builder
}

func (builder *NodeBuilder) Build() *Node {
	req := &Node{}
	if builder.nodeIdFlag {
		req.NodeId = &builder.nodeId

	}
	if builder.spaceIdFlag {
		req.SpaceId = &builder.spaceId

	}
	if builder.parentIdFlag {
		req.ParentId = &builder.parentId

	}
	if builder.objTypeFlag {
		req.ObjType = &builder.objType

	}
	if builder.titleFlag {
		req.Title = &builder.title

	}
	if builder.urlFlag {
		req.Url = &builder.url

	}
	if builder.iconFlag {
		req.Icon = &builder.icon

	}
	if builder.areaIdFlag {
		req.AreaId = &builder.areaId

	}
	if builder.sortIdFlag {
		req.SortId = &builder.sortId

	}
	if builder.domainFlag {
		req.Domain = &builder.domain

	}
	if builder.objTokenFlag {
		req.ObjToken = &builder.objToken

	}
	if builder.createTimeFlag {
		req.CreateTime = &builder.createTime

	}
	if builder.updateTimeFlag {
		req.UpdateTime = &builder.updateTime

	}
	if builder.deleteTimeFlag {
		req.DeleteTime = &builder.deleteTime

	}
	if builder.childNumFlag {
		req.ChildNum = &builder.childNum

	}
	if builder.versionFlag {
		req.Version = &builder.version

	}
	return req
}

type NodeChild struct {
}

type NodeChildBuilder struct {
}

func NewNodeChildBuilder() *NodeChildBuilder {
	builder := &NodeChildBuilder{}
	return builder
}

func (builder *NodeChildBuilder) Build() *NodeChild {
	req := &NodeChild{}
	return req
}

type Space struct {
	SpaceId *string `json:"space_id,omitempty"` // space的唯一标识

	Name *string `json:"name,omitempty"` // 名称

	Description *string `json:"description,omitempty"` // 描述

	AvatarUrl *string `json:"avatar_url,omitempty"` // 头像url

	TenantId *string `json:"tenant_id,omitempty"` // 所属租户id

	Domain *string `json:"domain,omitempty"` // 所在域名

	IsCrossTenant *bool `json:"is_cross_tenant,omitempty"` // 是否跨租户

	DefaultAttr *int `json:"default_attr,omitempty"` // 默认属性

	HomePage *SpaceHomePage `json:"home_page,omitempty"` // 空间主页

	CoverInfo *SpaceCoverInfo `json:"cover_info,omitempty"` // 空间封面

	Version *int `json:"version,omitempty"` // 版本号
}

type SpaceBuilder struct {
	spaceId     string // space的唯一标识
	spaceIdFlag bool

	name     string // 名称
	nameFlag bool

	description     string // 描述
	descriptionFlag bool

	avatarUrl     string // 头像url
	avatarUrlFlag bool

	tenantId     string // 所属租户id
	tenantIdFlag bool

	domain     string // 所在域名
	domainFlag bool

	isCrossTenant     bool // 是否跨租户
	isCrossTenantFlag bool

	defaultAttr     int // 默认属性
	defaultAttrFlag bool

	homePage     *SpaceHomePage // 空间主页
	homePageFlag bool

	coverInfo     *SpaceCoverInfo // 空间封面
	coverInfoFlag bool

	version     int // 版本号
	versionFlag bool
}

func NewSpaceBuilder() *SpaceBuilder {
	builder := &SpaceBuilder{}
	return builder
}

// space的唯一标识
//
// 示例值：
func (builder *SpaceBuilder) SpaceId(spaceId string) *SpaceBuilder {
	builder.spaceId = spaceId
	builder.spaceIdFlag = true
	return builder
}

// 名称
//
// 示例值：
func (builder *SpaceBuilder) Name(name string) *SpaceBuilder {
	builder.name = name
	builder.nameFlag = true
	return builder
}

// 描述
//
// 示例值：
func (builder *SpaceBuilder) Description(description string) *SpaceBuilder {
	builder.description = description
	builder.descriptionFlag = true
	return builder
}

// 头像url
//
// 示例值：
func (builder *SpaceBuilder) AvatarUrl(avatarUrl string) *SpaceBuilder {
	builder.avatarUrl = avatarUrl
	builder.avatarUrlFlag = true
	return builder
}

// 所属租户id
//
// 示例值：
func (builder *SpaceBuilder) TenantId(tenantId string) *SpaceBuilder {
	builder.tenantId = tenantId
	builder.tenantIdFlag = true
	return builder
}

// 所在域名
//
// 示例值：
func (builder *SpaceBuilder) Domain(domain string) *SpaceBuilder {
	builder.domain = domain
	builder.domainFlag = true
	return builder
}

// 是否跨租户
//
// 示例值：
func (builder *SpaceBuilder) IsCrossTenant(isCrossTenant bool) *SpaceBuilder {
	builder.isCrossTenant = isCrossTenant
	builder.isCrossTenantFlag = true
	return builder
}

// 默认属性
//
// 示例值：
func (builder *SpaceBuilder) DefaultAttr(defaultAttr int) *SpaceBuilder {
	builder.defaultAttr = defaultAttr
	builder.defaultAttrFlag = true
	return builder
}

// 空间主页
//
// 示例值：
func (builder *SpaceBuilder) HomePage(homePage *SpaceHomePage) *SpaceBuilder {
	builder.homePage = homePage
	builder.homePageFlag = true
	return builder
}

// 空间封面
//
// 示例值：
func (builder *SpaceBuilder) CoverInfo(coverInfo *SpaceCoverInfo) *SpaceBuilder {
	builder.coverInfo = coverInfo
	builder.coverInfoFlag = true
	return builder
}

// 版本号
//
// 示例值：
func (builder *SpaceBuilder) Version(version int) *SpaceBuilder {
	builder.version = version
	builder.versionFlag = true
	return builder
}

func (builder *SpaceBuilder) Build() *Space {
	req := &Space{}
	if builder.spaceIdFlag {
		req.SpaceId = &builder.spaceId

	}
	if builder.nameFlag {
		req.Name = &builder.name

	}
	if builder.descriptionFlag {
		req.Description = &builder.description

	}
	if builder.avatarUrlFlag {
		req.AvatarUrl = &builder.avatarUrl

	}
	if builder.tenantIdFlag {
		req.TenantId = &builder.tenantId

	}
	if builder.domainFlag {
		req.Domain = &builder.domain

	}
	if builder.isCrossTenantFlag {
		req.IsCrossTenant = &builder.isCrossTenant

	}
	if builder.defaultAttrFlag {
		req.DefaultAttr = &builder.defaultAttr

	}
	if builder.homePageFlag {
		req.HomePage = builder.homePage
	}
	if builder.coverInfoFlag {
		req.CoverInfo = builder.coverInfo
	}
	if builder.versionFlag {
		req.Version = &builder.version

	}
	return req
}

type SpaceCoverInfo struct {
	Origin *string `json:"origin,omitempty"` // 封面图片的url

	Thumbnail *string `json:"thumbnail,omitempty"` // 封面图片缩略图的url

	Name *string `json:"name,omitempty"` // 封面图片的名称

	IsGraphDark *bool `json:"is_graph_dark,omitempty"` // 封面是否为深色，如果为深色，则封面标题应当为白色，反之应当为黑色

	Color *string `json:"color,omitempty"` // 封面的色值
}

type SpaceCoverInfoBuilder struct {
	origin     string // 封面图片的url
	originFlag bool

	thumbnail     string // 封面图片缩略图的url
	thumbnailFlag bool

	name     string // 封面图片的名称
	nameFlag bool

	isGraphDark     bool // 封面是否为深色，如果为深色，则封面标题应当为白色，反之应当为黑色
	isGraphDarkFlag bool

	color     string // 封面的色值
	colorFlag bool
}

func NewSpaceCoverInfoBuilder() *SpaceCoverInfoBuilder {
	builder := &SpaceCoverInfoBuilder{}
	return builder
}

// 封面图片的url
//
// 示例值：
func (builder *SpaceCoverInfoBuilder) Origin(origin string) *SpaceCoverInfoBuilder {
	builder.origin = origin
	builder.originFlag = true
	return builder
}

// 封面图片缩略图的url
//
// 示例值：
func (builder *SpaceCoverInfoBuilder) Thumbnail(thumbnail string) *SpaceCoverInfoBuilder {
	builder.thumbnail = thumbnail
	builder.thumbnailFlag = true
	return builder
}

// 封面图片的名称
//
// 示例值：
func (builder *SpaceCoverInfoBuilder) Name(name string) *SpaceCoverInfoBuilder {
	builder.name = name
	builder.nameFlag = true
	return builder
}

// 封面是否为深色，如果为深色，则封面标题应当为白色，反之应当为黑色
//
// 示例值：
func (builder *SpaceCoverInfoBuilder) IsGraphDark(isGraphDark bool) *SpaceCoverInfoBuilder {
	builder.isGraphDark = isGraphDark
	builder.isGraphDarkFlag = true
	return builder
}

// 封面的色值
//
// 示例值：
func (builder *SpaceCoverInfoBuilder) Color(color string) *SpaceCoverInfoBuilder {
	builder.color = color
	builder.colorFlag = true
	return builder
}

func (builder *SpaceCoverInfoBuilder) Build() *SpaceCoverInfo {
	req := &SpaceCoverInfo{}
	if builder.originFlag {
		req.Origin = &builder.origin

	}
	if builder.thumbnailFlag {
		req.Thumbnail = &builder.thumbnail

	}
	if builder.nameFlag {
		req.Name = &builder.name

	}
	if builder.isGraphDarkFlag {
		req.IsGraphDark = &builder.isGraphDark

	}
	if builder.colorFlag {
		req.Color = &builder.color

	}
	return req
}

type SpaceHomePage struct {
	NodeId *string `json:"node_id,omitempty"` // 空间首页对应的node_id

	ObjToken *string `json:"obj_token,omitempty"` // 空间首页对应的obj_token

	ObjType *int `json:"obj_type,omitempty"` // 空间首页对应的obj_type

	Url *string `json:"url,omitempty"` // 空间首页url
}

type SpaceHomePageBuilder struct {
	nodeId     string // 空间首页对应的node_id
	nodeIdFlag bool

	objToken     string // 空间首页对应的obj_token
	objTokenFlag bool

	objType     int // 空间首页对应的obj_type
	objTypeFlag bool

	url     string // 空间首页url
	urlFlag bool
}

func NewSpaceHomePageBuilder() *SpaceHomePageBuilder {
	builder := &SpaceHomePageBuilder{}
	return builder
}

// 空间首页对应的node_id
//
// 示例值：
func (builder *SpaceHomePageBuilder) NodeId(nodeId string) *SpaceHomePageBuilder {
	builder.nodeId = nodeId
	builder.nodeIdFlag = true
	return builder
}

// 空间首页对应的obj_token
//
// 示例值：
func (builder *SpaceHomePageBuilder) ObjToken(objToken string) *SpaceHomePageBuilder {
	builder.objToken = objToken
	builder.objTokenFlag = true
	return builder
}

// 空间首页对应的obj_type
//
// 示例值：
func (builder *SpaceHomePageBuilder) ObjType(objType int) *SpaceHomePageBuilder {
	builder.objType = objType
	builder.objTypeFlag = true
	return builder
}

// 空间首页url
//
// 示例值：
func (builder *SpaceHomePageBuilder) Url(url string) *SpaceHomePageBuilder {
	builder.url = url
	builder.urlFlag = true
	return builder
}

func (builder *SpaceHomePageBuilder) Build() *SpaceHomePage {
	req := &SpaceHomePage{}
	if builder.nodeIdFlag {
		req.NodeId = &builder.nodeId

	}
	if builder.objTokenFlag {
		req.ObjToken = &builder.objToken

	}
	if builder.objTypeFlag {
		req.ObjType = &builder.objType

	}
	if builder.urlFlag {
		req.Url = &builder.url

	}
	return req
}

type SearchNodeReqBodyBuilder struct {
	query     string // 搜索关键词
	queryFlag bool

	spaceId     string // 文档所属的知识空间ID，为空搜索所有 wiki
	spaceIdFlag bool

	nodeId     string // wiki token，不为空搜索该节点及其所有子节点，为空搜索所有 wiki（根据 space_id 选择 space）
	nodeIdFlag bool
}

func NewSearchNodeReqBodyBuilder() *SearchNodeReqBodyBuilder {
	builder := &SearchNodeReqBodyBuilder{}
	return builder
}

// 搜索关键词
//
//示例值：123
func (builder *SearchNodeReqBodyBuilder) Query(query string) *SearchNodeReqBodyBuilder {
	builder.query = query
	builder.queryFlag = true
	return builder
}

// 文档所属的知识空间ID，为空搜索所有 wiki
//
//示例值：6967549310762221587
func (builder *SearchNodeReqBodyBuilder) SpaceId(spaceId string) *SearchNodeReqBodyBuilder {
	builder.spaceId = spaceId
	builder.spaceIdFlag = true
	return builder
}

// wiki token，不为空搜索该节点及其所有子节点，为空搜索所有 wiki（根据 space_id 选择 space）
//
//示例值：O5UIw9NA8iW308kQQeybWLZqcXc
func (builder *SearchNodeReqBodyBuilder) NodeId(nodeId string) *SearchNodeReqBodyBuilder {
	builder.nodeId = nodeId
	builder.nodeIdFlag = true
	return builder
}

func (builder *SearchNodeReqBodyBuilder) Build() *SearchNodeReqBody {
	req := &SearchNodeReqBody{}
	if builder.queryFlag {
		req.Query = &builder.query
	}
	if builder.spaceIdFlag {
		req.SpaceId = &builder.spaceId
	}
	if builder.nodeIdFlag {
		req.NodeId = &builder.nodeId
	}
	return req
}

type SearchNodePathReqBodyBuilder struct {
	query       string
	queryFlag   bool
	spaceId     string
	spaceIdFlag bool
	nodeId      string
	nodeIdFlag  bool
}

func NewSearchNodePathReqBodyBuilder() *SearchNodePathReqBodyBuilder {
	builder := &SearchNodePathReqBodyBuilder{}
	return builder
}

// 搜索关键词
//
// 示例值：123
func (builder *SearchNodePathReqBodyBuilder) Query(query string) *SearchNodePathReqBodyBuilder {
	builder.query = query
	builder.queryFlag = true
	return builder
}

// 文档所属的知识空间ID，为空搜索所有 wiki
//
// 示例值：6967549310762221587
func (builder *SearchNodePathReqBodyBuilder) SpaceId(spaceId string) *SearchNodePathReqBodyBuilder {
	builder.spaceId = spaceId
	builder.spaceIdFlag = true
	return builder
}

// wiki token，不为空搜索该节点及其所有子节点，为空搜索所有 wiki（根据 space_id 选择 space）
//
// 示例值：O5UIw9NA8iW308kQQeybWLZqcXc
func (builder *SearchNodePathReqBodyBuilder) NodeId(nodeId string) *SearchNodePathReqBodyBuilder {
	builder.nodeId = nodeId
	builder.nodeIdFlag = true
	return builder
}

func (builder *SearchNodePathReqBodyBuilder) Build() (*SearchNodeReqBody, error) {
	req := &SearchNodeReqBody{}
	if builder.queryFlag {
		req.Query = &builder.query
	}
	if builder.spaceIdFlag {
		req.SpaceId = &builder.spaceId
	}
	if builder.nodeIdFlag {
		req.NodeId = &builder.nodeId
	}
	return req, nil
}

type SearchNodeReqBuilder struct {
	apiReq *larkcore.ApiReq
	body   *SearchNodeReqBody
	limit  int // 最大返回多少记录，当使用迭代器访问时才有效
}

func NewSearchNodeReqBuilder() *SearchNodeReqBuilder {
	builder := &SearchNodeReqBuilder{}
	builder.apiReq = &larkcore.ApiReq{
		PathParams:  larkcore.PathParams{},
		QueryParams: larkcore.QueryParams{},
	}
	return builder
}

// 最大返回多少记录，当使用迭代器访问时才有效
func (builder *SearchNodeReqBuilder) Limit(limit int) *SearchNodeReqBuilder {
	builder.limit = limit
	return builder
}

// 分页标记，第一次请求不填，表示从头开始遍历；分页查询结果还有更多项时会同时返回新的 page_token，下次遍历可采用该page_token 获取查询结果
//
// 示例值：
func (builder *SearchNodeReqBuilder) PageToken(pageToken string) *SearchNodeReqBuilder {
	builder.apiReq.QueryParams.Set("page_token", fmt.Sprint(pageToken))
	return builder
}

// 分页大小
//
// 示例值：
func (builder *SearchNodeReqBuilder) PageSize(pageSize int) *SearchNodeReqBuilder {
	builder.apiReq.QueryParams.Set("page_size", fmt.Sprint(pageSize))
	return builder
}

//
func (builder *SearchNodeReqBuilder) Body(body *SearchNodeReqBody) *SearchNodeReqBuilder {
	builder.body = body
	return builder
}

func (builder *SearchNodeReqBuilder) Build() *SearchNodeReq {
	req := &SearchNodeReq{}
	req.apiReq = &larkcore.ApiReq{}
	req.Limit = builder.limit
	req.apiReq.QueryParams = builder.apiReq.QueryParams
	req.apiReq.Body = builder.body
	return req
}

type SearchNodeReqBody struct {
	Query *string `json:"query,omitempty"` // 搜索关键词

	SpaceId *string `json:"space_id,omitempty"` // 文档所属的知识空间ID，为空搜索所有 wiki

	NodeId *string `json:"node_id,omitempty"` // wiki token，不为空搜索该节点及其所有子节点，为空搜索所有 wiki（根据 space_id 选择 space）
}

type SearchNodeReq struct {
	apiReq *larkcore.ApiReq
	Body   *SearchNodeReqBody `body:""`
	Limit  int                // 最多返回多少记录，只有在使用迭代器访问时，才有效

}

type SearchNodeRespData struct {
	Items []*Node `json:"items,omitempty"` // 搜索到 wiki

	PageToken *string `json:"page_token,omitempty"` // 翻页 token，传入返回下一页，首页不需要传入

	HasMore *bool `json:"has_more,omitempty"` // 是否还有下一页
}

type SearchNodeResp struct {
	*larkcore.ApiResp `json:"-"`
	larkcore.CodeError
	Data *SearchNodeRespData `json:"data"` // 业务数据
}

func (resp *SearchNodeResp) Success() bool {
	return resp.Code == 0
}

type SearchNodeIterator struct {
	nextPageToken *string
	items         []*Node
	index         int
	limit         int
	ctx           context.Context
	req           *SearchNodeReq
	listFunc      func(ctx context.Context, req *SearchNodeReq, options ...larkcore.RequestOptionFunc) (*SearchNodeResp, error)
	options       []larkcore.RequestOptionFunc
	curlNum       int
}

func (iterator *SearchNodeIterator) Next() (bool, *Node, error) {
	// 达到最大量，则返回
	if iterator.limit > 0 && iterator.curlNum >= iterator.limit {
		return false, nil, nil
	}

	// 为0则拉取数据
	if iterator.index == 0 || iterator.index >= len(iterator.items) {
		if iterator.index != 0 && iterator.nextPageToken == nil {
			return false, nil, nil
		}
		if iterator.nextPageToken != nil {
			iterator.req.apiReq.QueryParams.Set("page_token", *iterator.nextPageToken)
		}
		resp, err := iterator.listFunc(iterator.ctx, iterator.req, iterator.options...)
		if err != nil {
			return false, nil, err
		}

		if resp.Code != 0 {
			return false, nil, errors.New(fmt.Sprintf("Code:%d,Msg:%s", resp.Code, resp.Msg))
		}

		if len(resp.Data.Items) == 0 {
			return false, nil, nil
		}

		iterator.nextPageToken = resp.Data.PageToken
		iterator.items = resp.Data.Items
		iterator.index = 0
	}

	block := iterator.items[iterator.index]
	iterator.index++
	iterator.curlNum++
	return true, block, nil
}

func (iterator *SearchNodeIterator) NextPageToken() *string {
	return iterator.nextPageToken
}
