package services

import "testing"

// Pure-Go tests for the SystemView registry. Each system view's specs
// must self-validate; the slugs must be reserved.

func TestSystemViews_AllValidate(t *testing.T) {
	for _, sv := range AllSystemViews() {
		t.Run(sv.Slug, func(t *testing.T) {
			if err := sv.Filter.Validate(); err != nil {
				t.Errorf("%s filter spec invalid: %v", sv.Slug, err)
			}
			if err := sv.Render.Validate(); err != nil {
				t.Errorf("%s render spec invalid: %v", sv.Slug, err)
			}
		})
	}
}

func TestSystemViews_SlugsReserved(t *testing.T) {
	for _, sv := range AllSystemViews() {
		t.Run(sv.Slug, func(t *testing.T) {
			if !IsReservedUserViewSlug(sv.Slug) {
				t.Errorf("system slug %q must be reserved against user_views", sv.Slug)
			}
		})
	}
}

func TestReservedSlugs_CaseFolded(t *testing.T) {
	if !IsReservedUserViewSlug("Dashboard") {
		t.Error("reserved-slug check must be case-insensitive")
	}
	if !IsReservedUserViewSlug("INBOX") {
		t.Error("reserved-slug check must be case-insensitive")
	}
}

func TestReservedSlugs_NonReservedAccepted(t *testing.T) {
	cases := []string{"freitag-stand", "approval-pending-mine", "siemens", "my-view"}
	for _, slug := range cases {
		if IsReservedUserViewSlug(slug) {
			t.Errorf("user-friendly slug %q must not be reserved", slug)
		}
	}
}
