package vm

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
	"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
)

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

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

func (l *GetOpenstackOverviewLogic) GetOpenstackOverview(req *types.OpenstackOverviewReq) (resp *types.OpenstackOverviewResp, err error) {
	// todo: add your logic here and delete this line
	var openstackOverview types.OpenstackOverview
	sqlStr := "SELECT t.max_total_cores,t.max_total_ram_size,t.max_total_volumes  FROM `vm_openstack_overview` t left join t_cluster tc on t.cluster_id=tc.id where tc.`name` = ?"
	l.svcCtx.DbEngin.Raw(sqlStr, req.Platform).Scan(&openstackOverview)
	resp = &types.OpenstackOverviewResp{
		Code: 200,
		Msg:  "success",
		Data: openstackOverview,
	}
	return resp, err
}
