package schema

import "github.com/nexuscrm/shared/pkg/models"

// ManagedRelationshipSemantics defines managed relationship semantics
// for a specific parent-child relationship.
type ManagedRelationshipSemantics struct {
	ChildObjectAPIName  string
	ParentObjectAPIName string
	FieldAPIName        string
	IsSharingParent     *bool
	CascadeDelete       *bool
	RestrictedDelete    *bool
}

// ManagedStandardObjectPolicy defines managed access policy for a standard object.
// Used by pack spec readers and assertions.
type ManagedStandardObjectPolicy struct {
	SharingModel           string
	EnableHierarchySharing bool
	AccessPolicy           *models.ObjectAccessPolicy
}

// substrateRelationshipSemantics contains managed relationship semantics for
// substrate objects (not standard CRM objects). Standard CRM object relationships
// (Contact→Account, Order→Account, Quote→Opportunity) are now in the pack spec.
var substrateRelationshipSemantics = []ManagedRelationshipSemantics{
	{
		ChildObjectAPIName:  "DashboardComponent",
		ParentObjectAPIName: "Dashboard",
		FieldAPIName:        "DashboardId",
		IsSharingParent:     boolPtr(true),
		CascadeDelete:       boolPtr(true),
	},
}

// ManagedStandardRelationshipSemanticsList returns substrate-level managed
// relationship semantics. Standard CRM object relationships are in the pack spec
// and should be read via packs.StandardRelationshipSemantics().
func ManagedStandardRelationshipSemanticsList() []ManagedRelationshipSemantics {
	out := make([]ManagedRelationshipSemantics, len(substrateRelationshipSemantics))
	copy(out, substrateRelationshipSemantics)
	return out
}

func boolPtr(v bool) *bool {
	return &v
}
