package permissions

import (
	"github.com/nexuscrm/kernel/pkg/formula"
	"github.com/nexuscrm/shared/pkg/models"
)

// SharingRuleCriteriaExpression normalizes the persisted SharingRule.Criteria
// surface. Formula text passes through unchanged; JSON array criteria are
// validated against object metadata before being rendered as a formula-shaped
// predicate for future read-path consumers.
func SharingRuleCriteriaExpression(raw string, schema *models.ObjectMetadata) (string, error) {
	return formula.SharingRuleCriteriaExpression(raw, schema)
}

// SharingRuleRecordAccessCriteriaExpression normalizes criteria for the
// single-record access gate. It intentionally supports a narrower JSON field
// set than the generic normalizer until rollup and datetime comparator
// semantics have dedicated query/record parity coverage.
func SharingRuleRecordAccessCriteriaExpression(raw string, schema *models.ObjectMetadata) (string, error) {
	return formula.SharingRuleRecordAccessCriteriaExpression(raw, schema)
}

// SharingRuleRuntimeCriteriaExpression normalizes criteria for runtime readers
// that must stay query/record-access compatible. It intentionally supports a
// narrower JSON field set than the generic normalizer until rollup and datetime
// comparator semantics have dedicated parity coverage.
func SharingRuleRuntimeCriteriaExpression(raw string, schema *models.ObjectMetadata) (string, error) {
	return formula.SharingRuleRuntimeCriteriaExpression(raw, schema)
}
