package framework

import (
	"time"
)

const ClusterScalerMockEmptyIdStr ClusterScalerType = "ClusterScalerMockEmpty"

var ClusterScalerMockEmptyMeta = &ClusterScalerMeta{
	ScalerMeta: UnattachedScalerMeta{
		Type:             ClusterScalerMockEmptyIdStr,
		InterfaceVersion: ClusterScalerInterfaceV1IdStr,
	},
	InputMeta:  InputProviderMockEmptyMeta,
	OutputMeta: OutputMockEmptyMeta,
}

type ClusterScalerMockEmpty struct {
	eventReceiver EventReceiver
	clusterId     ClusterId
	input         InputInterfaceV1
	output        OutputInterfaceV1
}

func NewClusterScalerMockEmpty(
	eventReceiver EventReceiver,
	clusterId ClusterId,
	input InputInterfaceV1,
	output OutputInterfaceV1) *ClusterScalerMockEmpty {

	return &ClusterScalerMockEmpty{
		eventReceiver: eventReceiver,
		clusterId:     clusterId,
		input:         input,
		output:        output,
	}
}

func (this *ClusterScalerMockEmpty) PullNewClusterTopology(currentTopology ClusterTopologyV1) (ClusterTopologyV1, error) {
	this.eventReceiver.OnEvent(
		EventClusterScalerV1PullNewClusterTopologyBegin,
		EventDataWithName("ClusterId", CloneableString(this.clusterId)))

	fromTo := NewTimeRangeLatest(5 * 60 * time.Second)
	metricValues, err := this.input.GetRangeMetrics(this.clusterId, InputMetricNameTiDBCPUUsageAll, fromTo)
	if err != nil {
		return nil, err
	}

	// calculate the expected topology based on:
	_ = metricValues
	_ = currentTopology

	this.eventReceiver.OnEvent(
		EventClusterScalerV1PullNewClusterTopologyEnd,
		EventDataWithName("ClusterId", CloneableString(this.clusterId)))

	// return the calculated new (expected) topology
	return currentTopology, nil

	// the caller later:
	// output.SetNewClusterTopology(...)
}
