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

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

func (l *GetBadgeConfigDetailLogic) GetBadgeConfigDetail(in *plant.IdReq) (*plant.BadgeConfigInfo, error) {
	var badge plantModel.BadgeConfig
	if err := l.svcCtx.DB.Where("id = ?", in.Id).First(&badge).Error; err != nil {
		return nil, err
	}
	return &plant.BadgeConfigInfo{
		Id: badge.ID, Name: badge.Name, Description: badge.Description, Dimension: badge.Dimension,
		GroupId: badge.GroupID, Tier: int32(badge.Tier), TargetAction: badge.TargetAction,
		Threshold: badge.Threshold, RewardSunlight: badge.RewardSunlight, IconId: badge.IconID, Sort: int32(badge.Sort),
	}, nil
}
