package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"jyBXCore/rpc/entity"
	IC "jyBXCore/rpc/init"
	"jyBXCore/rpc/internal/svc"
	"jyBXCore/rpc/type/bxcore"
)

type PolymerizeSearchLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPolymerizeSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PolymerizeSearchLogic {
	return &PolymerizeSearchLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 聚合搜索
func (l *PolymerizeSearchLogic) PolymerizeSearch(in *bxcore.PolymerizeSearchReq) (*bxcore.PolymerizeSearchResp, error) {
	// todo: add your logic here and delete this line
	if in.SearchCode == "" {
		return &bxcore.PolymerizeSearchResp{}, nil
	}
	data := &bxcore.SearchReturn{}
	IC.Search_Thread <- true
	ks := entity.NewKeyWordsSearch()
	defer func() {
		<-IC.Search_Thread
	}()
	data = ks.PolymerizeSearch(in)
	return &bxcore.PolymerizeSearchResp{
		ErrCode: 0,
		ErrMsg:  "",
		Data:    data,
	}, nil
}
