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

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

func (l *GetLevelConfigDetailLogic) GetLevelConfigDetail(in *plant.IdReq) (*plant.LevelConfigInfo, error) {
	var lc plantModel.LevelConfig
	if err := l.svcCtx.DB.First(&lc, "id = ?", in.Id).Error; err != nil {
		return nil, err
	}
	return &plant.LevelConfigInfo{
		Id: lc.ID, Level: int32(lc.Level), Title: lc.Title,
		MinSunlight: lc.MinSunlight, Perks: lc.Perks,
	}, nil
}
