package core

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"
	"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/tracker"
	tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
)

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

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

func (l *SyncClusterLoadLogic) SyncClusterLoad(req *types.SyncClusterLoadReq) error {
	if nil != req.ClusterLoadRecords {
		for _, record := range req.ClusterLoadRecords {
			var param tracker.ClusterLoadRecord
			tool.Convert(record, &param)
			tracker.SyncClusterLoad(param)
		}
	}
	return nil
}
