package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	plantModel "sundynix-micro-go/app/plant/model"
	"sundynix-micro-go/app/plant/rpc/internal/svc"
	"sundynix-micro-go/app/plant/rpc/plant"
)

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

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

func (l *UpdateWikiClassLogic) UpdateWikiClass(in *plant.UpdateWikiClassReq) (*plant.CommonResp, error) {
	updates := map[string]interface{}{"name": in.Name, "oss_id": in.Icon}
	if err := l.svcCtx.DB.Model(&plantModel.WikiClass{}).Where("id = ?", in.Id).Updates(updates).Error; err != nil {
		return nil, err
	}
	return &plant.CommonResp{Code: 0, Msg: "ok"}, nil
}
