package reportproxy

import (
	"sort"
	"testing"
)

// unionKeys returns the sorted union of both map keysets so a missing entry
// on either side surfaces as its own failing subtest row.
func unionKeys() []string {
	seen := map[string]struct{}{}
	for k := range templatePerms {
		seen[k] = struct{}{}
	}
	for k := range templateModule {
		seen[k] = struct{}{}
	}
	keys := make([]string, 0, len(seen))
	for k := range seen {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	return keys
}

func TestTemplatePerms_MatchModule(t *testing.T) {
	for _, tpl := range unionKeys() {
		t.Run(tpl, func(t *testing.T) {
			if _, ok := templatePerms[tpl]; !ok {
				t.Errorf("template %q in templateModule but missing from templatePerms", tpl)
			}
			if _, ok := templateModule[tpl]; !ok {
				t.Errorf("template %q in templatePerms but missing from templateModule", tpl)
			}
		})
	}
}

func TestTemplatePerms_NonEmpty(t *testing.T) {
	for _, tpl := range unionKeys() {
		t.Run(tpl, func(t *testing.T) {
			if templatePerms[tpl] == "" {
				t.Errorf("template %q has empty permission string", tpl)
			}
		})
	}
}

func TestFormatContentType(t *testing.T) {
	cases := []struct{ format, ct string }{
		{"pdf", "application/pdf"},
		{"html", "text/html; charset=utf-8"},
	}
	for _, tc := range cases {
		t.Run(tc.format, func(t *testing.T) {
			if got := formatContentType[tc.format]; got != tc.ct {
				t.Errorf("formatContentType[%q] = %q, want %q", tc.format, got, tc.ct)
			}
		})
	}
}


func TestTemplateCount(t *testing.T) {
	if got := len(templatePerms); got < 25 {
		t.Errorf("len(templatePerms) = %d, want >= 25", got)
	}
	if got := len(templateModule); got < 25 {
		t.Errorf("len(templateModule) = %d, want >= 25", got)
	}
}
