package core

import (
	"context"

	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

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

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

func (l *GetPublicFlavorLogic) GetPublicFlavor(req *types.PublicFlavorReq) (resp *types.PublicFlavorResp, err error) {
	// todo: add your logic here and delete this line
	resp = &types.PublicFlavorResp{}
	var flavorDict []types.FlavorDict
	sqlStrTask := "SELECT * FROM `vm_flavor_dict`"
	txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&flavorDict)
	if txTask.Error != nil {
		logx.Error(err)
		return nil, txTask.Error
	}
	resp.Code = 200
	resp.Message = "success"
	resp.FlavorDict = flavorDict
	return resp, nil
}
