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

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

func (l *CreateBadgeConfigLogic) CreateBadgeConfig(in *plant.CreateBadgeConfigReq) (*plant.CommonResp, error) {
	cfg := plantModel.BadgeConfig{
		Name: in.Name, Description: in.Description, Dimension: in.Dimension,
		GroupID: in.GroupId, Tier: int(in.Tier), TargetAction: in.TargetAction,
		Threshold: in.Threshold, RewardSunlight: in.RewardSunlight,
		IconID: in.IconId, Sort: int(in.Sort),
	}
	if err := l.svcCtx.DB.Create(&cfg).Error; err != nil {
		return nil, err
	}
	return &plant.CommonResp{Code: 0, Msg: "ok"}, nil
}
