// Code generated by Lark OpenAPI.

package larkwiki

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

type V1 struct {
	Node *node // 知识库
}

func New(config *larkcore.Config) *V1 {
	return &V1{
		Node: &node{config: config},
	}
}

type node struct {
	config *larkcore.Config
}

// Search
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/document/ukTMukTMukTM/uEzN0YjLxcDN24SM3QjN/search_wiki
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/wikiv1/search_node.go
func (n *node) Search(ctx context.Context, req *SearchNodeReq, options ...larkcore.RequestOptionFunc) (*SearchNodeResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/wiki/v1/nodes/search"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeUser}
	apiResp, err := larkcore.Request(ctx, apiReq, n.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &SearchNodeResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, n.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}
func (n *node) SearchByIterator(ctx context.Context, req *SearchNodeReq, options ...larkcore.RequestOptionFunc) (*SearchNodeIterator, error) {
	return &SearchNodeIterator{
		ctx:      ctx,
		req:      req,
		listFunc: n.Search,
		options:  options,
		limit:    req.Limit}, nil
}
