package smtp

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

type MetricsStore struct {
	backend   SMTPStore
	mailTotal *prometheus.CounterVec
}

func NewMetricsStore(backend SMTPStore) *MetricsStore {
	store := &MetricsStore{backend: backend}

	store.mailTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name:        "apiary_smtp_received_total",
			Help:        "Total count of received emails.",
			ConstLabels: prometheus.Labels{"service": "honeypot_smtp"},
		},
		[]string{"from"},
	)
	prometheus.MustRegister(store.mailTotal)

	return store
}

func (s *MetricsStore) AddMailData(data *MailData) error {
	s.mailTotal.WithLabelValues(data.From).Inc()

	return s.backend.AddMailData(data)
}
