package entity

import (
	"testing"
	"time"
)

func TestTenantTokenTTLCapsAtTwoHours(t *testing.T) {
	testCases := []struct {
		name      string
		requested time.Duration
		want      time.Duration
	}{
		{name: "uses default for zero", requested: 0, want: MaxTenantKubeconfigTTL},
		{name: "keeps shorter ttl", requested: 30 * time.Minute, want: 30 * time.Minute},
		{name: "caps longer ttl", requested: 24 * time.Hour, want: MaxTenantKubeconfigTTL},
	}

	for _, tc := range testCases {
		if got := TenantTokenTTL(tc.requested); got != tc.want {
			t.Fatalf("%s: expected %s, got %s", tc.name, tc.want, got)
		}
	}
}

func TestTenantBindingWithDefaults(t *testing.T) {
	binding := NewTenantBinding("tenant-a").WithDefaults()

	if err := binding.Validate(); err != nil {
		t.Fatalf("expected valid default binding: %v", err)
	}
	if binding.ServiceAccountName != DefaultTenantServiceAccountName {
		t.Fatalf("expected default service account %q, got %q", DefaultTenantServiceAccountName, binding.ServiceAccountName)
	}
	if binding.Labels["ocdp.io/tenant"] != "tenant-a" {
		t.Fatalf("expected tenant label, got %#v", binding.Labels)
	}
}
