package myPlant

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

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

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

func (l *AddCareRecordLogic) AddCareRecord(req *types.CareRecordReq) error {
	userId := fmt.Sprintf("%v", l.ctx.Value("userId"))
	_, err := l.svcCtx.PlantRpc.AddCareRecord(l.ctx, &plant.AddCareRecordReq{
		UserId: userId, PlantId: req.PlantId, PlanId: req.PlanId, Action: req.Action, Note: req.Note,
	})
	return err
}
