package domain import ( "fmt" "strings" ) // ValidateStimulusBlockKeyReferences ensures each membership references a known block key. func ValidateStimulusBlockKeyReferences(memberships []QuestionSetMembership, blockKeys map[string]struct{}) error { for _, m := range memberships { if m.StimulusBlockKey == nil { continue } key := strings.TrimSpace(*m.StimulusBlockKey) if key == "" { return fmt.Errorf("stimulus_block_key cannot be empty") } if _, ok := blockKeys[key]; !ok { return fmt.Errorf("stimulus_block_key %q does not match a stimulus block on this practice", key) } } return nil }