package metric

import (
	"github.com/prometheus/client_golang/prometheus"
	"github.com/tidbcloud/dataflow-service/app/repo/entity"
)

const (
	NS                   = "dataflow"
	SUBSYSTEM_CHANGEFEED = "changefeed"

	ClusterIDLabel    = "cluster_id"
	ChangefeedIDLabel = "changefeed_id"
)

var commonLabels = []string{ClusterIDLabel, ChangefeedIDLabel}

var (
	//nolint:gomnd
	ChangefeedStatusIntMap = map[entity.CDCStatus]int{
		entity.CDCStatusCreating: 0,
		entity.CDCStatusNormal:   1,
		entity.CDCStatusDeleting: 2,
		entity.CDCStatusDeleted:  3,
		entity.CDCStatusError:    4,
		entity.CDCStatusFailed:   5,
		entity.CDCStatusStarting: 6,
		entity.CDCStatusStopping: 7,
		entity.CDCStatusStopped:  8,
		entity.CDCStatusScaling:  9,
	}

	ChangefeedStatusDesc = prometheus.NewDesc(
		prometheus.BuildFQName(NS, SUBSYSTEM_CHANGEFEED, "status_desc"),
		"the status of changefeed tasks",
		commonLabels, nil)

	ChangefeedStatus = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: NS,
			Subsystem: SUBSYSTEM_CHANGEFEED,
			Name:      "status",
			Help: "backup status: 0 - creating, 1 - normal, 2 - deleting, 3 - deleted, 4 - error, 5 - failed," +
				" 6 - starting, 7 - stopping, 8 - stopped, 9 - scaling",
			ConstLabels: nil,
		}, commonLabels)
)
