package bootstrapimpl

import (
	"reflect"
	"slices"
	"testing"

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

func TestDefaultPlatformStandardFieldsIncludesRecordTypeID(t *testing.T) {
	fields := DefaultPlatformStandardFields()
	if !slices.Contains(fields, constants.FieldRecordTypeID) {
		t.Fatalf("DefaultPlatformStandardFields() missing %s: %#v", constants.FieldRecordTypeID, fields)
	}
}

func TestFieldDeclsFromRawSynthesizesCompoundParentFromChildMetadata(t *testing.T) {
	decls := fieldDeclsFromRaw([]fpFieldDeclRaw{
		{APIName: "Salutation", CompoundFieldName: "Name"},
		{APIName: "FirstName", CompoundFieldName: "Name"},
		{APIName: "LastName", CompoundFieldName: "Name"},
	})

	classifier := fieldprovenance.BuildClassifier(
		nil,
		[]fieldprovenance.ObjectDeclaration{{APIName: "Contact", Fields: decls}},
		nil,
		DefaultPlatformStandardFields(),
	)
	ok, components := classifier.ClassifyCompound("Contact", "Name")
	if !ok {
		t.Fatal("Contact.Name compound = false, want true")
	}
	if want := []string{"Salutation", "FirstName", "LastName"}; !reflect.DeepEqual(components, want) {
		t.Fatalf("Contact.Name components = %#v, want %#v", components, want)
	}
}
