package services

// Pure-function tests for DashboardService extensions in Slice A3.

import (
	"context"
	"testing"

	"github.com/google/uuid"

	"mgit.msbls.de/m/paliad/internal/models"
)

func TestDashboardService_InboxSummary_NilApprovalsIsNoop(t *testing.T) {
	s := &DashboardService{} // approvals nil
	data := &DashboardData{}
	user := &models.User{ID: uuid.New()}
	if err := s.loadInboxSummary(context.Background(), data, user); err != nil {
		t.Fatalf("loadInboxSummary with nil approvals returned %v; want nil", err)
	}
	if data.InboxSummary.PendingCount != 0 {
		t.Errorf("PendingCount=%d; want 0", data.InboxSummary.PendingCount)
	}
	if data.InboxSummary.Top == nil {
		t.Errorf("Top is nil; want empty slice")
	}
	if len(data.InboxSummary.Top) != 0 {
		t.Errorf("Top has %d entries; want 0", len(data.InboxSummary.Top))
	}
}

func TestDashboardService_SetApprovalService_WiringWorks(t *testing.T) {
	s := &DashboardService{}
	if s.approvals != nil {
		t.Fatalf("freshly-constructed DashboardService has non-nil approvals")
	}
	a := &ApprovalService{} // empty shell; we only check the pointer wiring
	s.SetApprovalService(a)
	if s.approvals != a {
		t.Errorf("SetApprovalService did not wire the pointer")
	}
}

func TestInboxTopCap_NonZero(t *testing.T) {
	// Sanity guard: if someone zeros this const, the inbox-approvals
	// widget falls back to an empty top-N silently. Pin it ≥ the
	// largest catalog count option for the inbox widget (10).
	if InboxTopCap < 10 {
		t.Errorf("InboxTopCap=%d; must be ≥ 10 to satisfy widget catalog max count", InboxTopCap)
	}
}
