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

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

// 更新植物
func (l *UpdatePlantLogic) UpdatePlant(in *plant.UpdatePlantReq) (*plant.CommonResp, error) {
	updateMap := map[string]interface{}{
		"name":              in.Name,
		"placement":         in.Placement,
		"pot_material":      in.PotMaterial,
		"pot_size":          in.PotSize,
		"sunlight":          in.Sunlight,
		"planting_material": in.PlantingMaterial,
	}
	if err := l.svcCtx.DB.Model(&plantModel.MyPlant{}).Where("id = ?", in.Id).Updates(updateMap).Error; err != nil {
		return nil, err
	}
	return &plant.CommonResp{Code: 0, Msg: "ok"}, nil
}
