package metrics

import (
	"github.com/prometheus/client_golang/prometheus"
)

const (
	ginSubsystem = "gin"
)

var (
	Gin *ginMetrics
)

func RegisterGinMetrics(namespace string) {
	Gin = &ginMetrics{
		ReqDur: prometheus.NewHistogramVec(
			prometheus.HistogramOpts{
				Namespace: namespace,
				Subsystem: ginSubsystem,
				Name:      "request_duration_seconds",
				Help:      "The HTTP request latencies in seconds.",
			},
			[]string{"code", "method", "url"},
		),
		RespSize: prometheus.NewSummary(
			prometheus.SummaryOpts{
				Namespace: namespace,
				Subsystem: ginSubsystem,
				Name:      "response_size_bytes",
				Help:      "The HTTP response sizes in bytes.",
			},
		),
	}

	prometheus.MustRegister(
		Gin.ReqDur, Gin.RespSize,
	)
}

type ginMetrics struct {
	ReqDur   *prometheus.HistogramVec
	RespSize prometheus.Summary
}
