package wiki

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

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

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

func (l *UpdateWikiLogic) UpdateWiki(req *types.UpdateWikiReq) error {
	_, err := l.svcCtx.PlantRpc.UpdateWiki(l.ctx, &plantPb.UpdateWikiReq{
		Id: req.Id, Name: req.Name, LatinName: req.LatinName, Aliases: req.Aliases,
		Genus: req.Genus, Difficulty: int32(req.Difficulty), IsHot: int32(req.IsHot),
		GrowthHabit: req.GrowthHabit, LightIntensity: req.LightIntensity,
		OptimalTempPeriod: req.OptimalTempPeriod, ClassId: req.ClassId,
		DistributionArea: req.DistributionArea, LifeCycle: req.LifeCycle,
		ClassIds: req.ClassIds, OssIds: req.OssIds, RelatedWikiIds: req.RelatedWikiIds,
		ReproductionMethod: req.ReproductionMethod, PestsDiseases: req.PestsDiseases,
		LightType: req.LightType, Stem: req.Stem, Fruit: req.Fruit,
		FoliageType: req.FoliageType, FoliageColor: req.FoliageColor,
		FoliageShape: req.FoliageShape, Height: int32(req.Height),
		FloweringPeriod: req.FloweringPeriod, FloweringColor: req.FloweringColor,
		FloweringShape: req.FloweringShape, FloweringDiameter: int32(req.FlowerDiameter),
	})
	return err
}
