package metrics

import (
	"time"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
	dbQueryCounter = promauto.NewCounterVec(prometheus.CounterOpts{
		Namespace: "app",
		Name:      "db_queries_total",
		Help:      "Total DB queries",
	}, []string{"category", "error"})

	dbQueryDurationHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
		Namespace: "app",
		Name:      "db_query_duration_seconds",
		Help:      "Latency of DB queries, seconds",
		Buckets:   prometheus.DefBuckets,
	}, []string{"category", "error"})
)

func IncDBQueryCount(cat, errLabel string) {
	dbQueryCounter.WithLabelValues(cat, errLabel).Inc()
}

func StoreDBQueryDuration(cat, errLabel string, d time.Duration) {
	dbQueryDurationHistogram.WithLabelValues(cat, errLabel).Observe(d.Seconds())
}
