package files

import (
	"testing"

	"github.com/nexuscrm/backend/internal/features/mru"
)

func TestNormalizeParentObjectAPIName(t *testing.T) {
	mru.RegisterKeyPrefix("0Q0", "quote")

	tests := []struct {
		name         string
		parentID     string
		parentObject string
		want         string
	}{
		{name: "standard id wins", parentID: "0Q0RC000005YRUL0A4", parentObject: "quote", want: "Quote"},
		{name: "inferred lowercase quote metadata canonicalized", parentID: "0Q0RC000005YRUL0A4", parentObject: "", want: "Quote"},
		{name: "known lowercase canonicalized", parentID: "custom-parent-id", parentObject: "contract", want: "Contract"},
		{name: "system comment canonicalized", parentID: "custom-parent-id", parentObject: "comment", want: "_System_Comment"},
		{name: "unknown preserved", parentID: "custom-parent-id", parentObject: "MyCustomObject__c", want: "MyCustomObject__c"},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			if got := NormalizeParentObjectAPIName(tc.parentID, tc.parentObject); got != tc.want {
				t.Fatalf("NormalizeParentObjectAPIName() = %q, want %q", got, tc.want)
			}
		})
	}
}
