// Code scaffolded by goctl. Safe to edit.
// goctl 1.10.1

package persona

import (
	"context"

	"haixun-backend/internal/svc"
	"haixun-backend/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

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

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

func (l *ListKnowledgeChunksLogic) ListKnowledgeChunks(req *types.PersonaPath) (resp *types.ListKnowledgeChunksData, err error) {
	tenantID, uid, err := actorFrom(l.ctx)
	if err != nil {
		return nil, err
	}
	items, err := l.svcCtx.ContentOps.ListKnowledgeChunks(l.ctx, tenantID, uid, req.ID, 80)
	if err != nil {
		return nil, err
	}
	list := make([]types.KnowledgeChunkData, 0, len(items))
	for _, item := range items {
		list = append(list, toKnowledgeChunkData(item))
	}
	return &types.ListKnowledgeChunksData{List: list}, nil
}
