package metrics

import (
	"testing"
	"time"

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

func TestBusinessMetrics_Recorders(t *testing.T) {
	Init()

	m := DefaultPrometheus()
	if m == nil {
		t.Fatal("expected Prometheus metrics to be initialized")
	}

	userBefore := testutil.ToFloat64(m.UserCreatedTotal.WithLabelValues("human"))
	IncUserCreated("human")
	if got := testutil.ToFloat64(m.UserCreatedTotal.WithLabelValues("human")); got != userBefore+1 {
		t.Fatalf("user_created_total: got %v, want %v", got, userBefore+1)
	}

	pushBefore := testutil.ToFloat64(m.GitPushTotal)
	IncGitPush()
	if got := testutil.ToFloat64(m.GitPushTotal); got != pushBefore+1 {
		t.Fatalf("git_push_total: got %v, want %v", got, pushBefore+1)
	}

	SetActiveUsersDaily(3)
	if got := testutil.ToFloat64(m.ActiveUsersDaily); got != 3 {
		t.Fatalf("active_users_daily: got %v, want 3", got)
	}

	ObserveUserActivationDuration(2 * time.Minute)
	if got := testutil.CollectAndCount(m.UserActivationDuration); got == 0 {
		t.Fatal("expected user activation histogram to collect samples")
	}
}
