package uiapi

import (
	"testing"

	"github.com/nexuscrm/shared/pkg/constants"
)

// =============================================================================
// isSystemAuditField — pure function
// =============================================================================

func TestIsSystemAuditField(t *testing.T) {
	tests := []struct {
		name     string
		apiName  string
		expected bool
	}{
		{"Id is system audit field", constants.FieldID, true},
		{"CreatedDate is system audit field", constants.FieldCreatedDate, true},
		{"CreatedById is system audit field", constants.FieldCreatedByID, true},
		{"LastModifiedDate is system audit field", constants.FieldLastModifiedDate, true},
		{"LastModifiedById is system audit field", constants.FieldLastModifiedByID, true},
		{"Name is NOT system audit field", "Name", false},
		{"OwnerId is NOT system audit field", "OwnerId", false},
		{"Description is NOT system audit field", "Description", false},
		{"empty string is NOT system audit field", "", false},
		{"SystemModstamp is NOT system audit field", constants.FieldSystemModstamp, false},
		{"Custom__c is NOT system audit field", "Custom__c", false},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := isSystemAuditField(tt.apiName)
			if got != tt.expected {
				t.Errorf("isSystemAuditField(%q) = %v, want %v", tt.apiName, got, tt.expected)
			}
		})
	}
}

// =============================================================================
// valueToDisplayString — pure function
// =============================================================================

func TestValueToDisplayString(t *testing.T) {
	tests := []struct {
		name     string
		input    interface{}
		expected string
	}{
		{"nil returns empty string", nil, ""},
		{"string value passes through", "hello", "hello"},
		{"empty string passes through", "", ""},
		{"float64 integer", float64(42), "42"},
		{"float64 decimal", float64(3.14), "3.14"},
		{"float64 zero", float64(0), "0"},
		{"float64 negative", float64(-1.5), "-1.5"},
		{"bool true", true, "true"},
		{"bool false", false, "false"},
		{"int uses Sprintf fallback", 123, "123"},
		{"slice uses Sprintf fallback", []string{"a"}, "[a]"},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := valueToDisplayString(tt.input)
			if got != tt.expected {
				t.Errorf("valueToDisplayString(%v) = %q, want %q", tt.input, got, tt.expected)
			}
		})
	}
}
