package logic

import (
	"context"

	plantModel "sundynix-micro-go/app/plant/model"
	"sundynix-micro-go/app/plant/rpc/internal/svc"
	"sundynix-micro-go/app/plant/rpc/plant"

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

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

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

// 百科分类列表
func (l *GetWikiClassListLogic) GetWikiClassList(in *plant.IdReq) (*plant.WikiClassListResp, error) {
	var list []plantModel.WikiClass
	if err := l.svcCtx.DB.Order("created_at asc").Find(&list).Error; err != nil {
		return nil, err
	}
	var result []*plant.WikiClassInfo
	for _, item := range list {
		result = append(result, &plant.WikiClassInfo{
			Id:    item.ID,
			Name:  item.Name,
			OssId: item.OssID,
		})
	}
	return &plant.WikiClassListResp{List: result}, nil
}
