package schema

import (
	"testing"

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

func TestFindRollupChildDependenciesMatchesChildObjectCaseInsensitively(t *testing.T) {
	parent := &models.ObjectMetadata{
		APIName: "Project__c",
		Fields: []models.FieldMetadata{
			{
				APIName: "TotalBudget__c",
				Type:    constants.FieldTypeRollupSummary,
				RollupConfig: &models.RollupConfig{
					CalcType:          "SUM",
					SummaryObject:     "Task__c",
					SummaryField:      "Budget__c",
					RelationshipField: "ProjectId__c",
				},
			},
		},
	}

	deps := FindRollupChildDependencies([]*models.ObjectMetadata{parent}, "task__C")
	if len(deps) != 1 {
		t.Fatalf("FindRollupChildDependencies() len = %d, want 1", len(deps))
	}
	if deps[0].ParentObjectAPIName != "Project__c" {
		t.Fatalf("ParentObjectAPIName = %q, want Project__c", deps[0].ParentObjectAPIName)
	}
	if deps[0].RollupField.APIName != "TotalBudget__c" {
		t.Fatalf("RollupField.APIName = %q, want TotalBudget__c", deps[0].RollupField.APIName)
	}
}
