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

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

// 配置 - 等级配置列表
func (l *GetLevelConfigListLogic) GetLevelConfigList(in *plant.PageReq) (*plant.LevelConfigListResp, error) {
	var list []plantModel.LevelConfig
	if err := l.svcCtx.DB.Order("level asc").Find(&list).Error; err != nil {
		return nil, err
	}

	var result []*plant.LevelConfigInfo
	for _, item := range list {
		result = append(result, &plant.LevelConfigInfo{
			Id:          item.ID,
			Level:       int32(item.Level),
			Title:       item.Title,
			MinSunlight: item.MinSunlight,
			Perks:       item.Perks,
		})
	}

	return &plant.LevelConfigListResp{List: result}, nil
}
