package tidbupgrader

import (
	"fmt"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/tidbcloud/aws-shared-provider/pkg/metrics"
)

type upgradeRecord struct {
	revision string

	tryTickCount               int
	preOldPodInAssignCacheSize int
}

func (r upgradeRecord) String() string {
	return fmt.Sprintf("revision: %s, tryTickCount: %d, preOldPodInAssignCacheSize: %d",
		r.revision, r.tryTickCount, r.preOldPodInAssignCacheSize)
}

func (tu *TidbUpgrader) initRecord() {
	if tu.record.revision != "" {
		metrics.OldPodFreeCacheSizeGauge.DeletePartialMatch(prometheus.Labels{"revision": tu.record.revision})
		metrics.FreeCacheSizeGauge.DeletePartialMatch(prometheus.Labels{"revision": tu.record.revision})
		metrics.OldPodAssignCacheSizeGauge.DeletePartialMatch(prometheus.Labels{"revision": tu.record.revision})
		metrics.AssignCacheSizeGauge.DeletePartialMatch(prometheus.Labels{"revision": tu.record.revision})
	}

	tu.record = upgradeRecord{revision: tu.tidbPool.Revision}
}
