package provider

import (
	"strings"
	"sync"

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

var (
	metricsOnce sync.Once

	cardPayoutCallbacks *prometheus.CounterVec
)

func initMetrics() {
	metricsOnce.Do(func() {
		cardPayoutCallbacks = promauto.NewCounterVec(prometheus.CounterOpts{
			Namespace: "sendico",
			Subsystem: "aurora_gateway",
			Name:      "card_payout_callbacks_total",
			Help:      "Aurora card payout callbacks grouped by provider status.",
		}, []string{"status"})
	})
}

// ObserveCallback records callback status for Aurora card payouts.
func ObserveCallback(status string) {
	initMetrics()
	status = strings.TrimSpace(status)
	if status == "" {
		status = "unknown"
	}
	status = strings.ToLower(status)
	if cardPayoutCallbacks != nil {
		cardPayoutCallbacks.WithLabelValues(status).Inc()
	}
}
