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 CreateWikiClassLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

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

// 创建百科分类
func (l *CreateWikiClassLogic) CreateWikiClass(in *plant.CreateWikiClassReq) (*plant.CommonResp, error) {
	wikiClass := plantModel.WikiClass{
		Name:  in.Name,
		OssID: in.Icon,
	}
	if err := l.svcCtx.DB.Create(&wikiClass).Error; err != nil {
		return nil, err
	}
	return &plant.CommonResp{Code: 0, Msg: "ok"}, nil
}
