package packs

type ObjectSpecValueDecision int

const (
	ObjectSpecValueExactRequired ObjectSpecValueDecision = iota
	ObjectSpecValueLiveOverrideAllowed
)

func ResolveObjectSpecValueOwnership(manageability Manageability, isCustomized bool) ObjectSpecValueDecision {
	if manageability == ManageabilityDefaultsOnly && isCustomized {
		return ObjectSpecValueLiveOverrideAllowed
	}
	return ObjectSpecValueExactRequired
}

// ResolveDefaultChildRowsValueOwnership is the sole ownership oracle for
// per-spec _System_Object.DefaultChildRows decisions.
//
// Resolver-first contract: any verify path that consumes live-row
// DefaultChildRows ownership must consult this helper before fail-closed live
// validation. Spec-shape validators that only validate authored pack / overlay
// payloads are outside that rule.
func ResolveDefaultChildRowsValueOwnership(manageability Manageability, defaultChildRowsCustomized bool) ObjectSpecValueDecision {
	return ResolveObjectSpecValueOwnership(manageability, defaultChildRowsCustomized)
}

// ResolveChildCloneRulesValueOwnership is the ownership oracle for per-spec
// _System_Object.ChildCloneRules decisions. ChildCloneRules uses a
// column-scoped customization bit so unrelated object-row customization cannot
// suppress pack reapply or mask drift on the executable child-clone fact.
func ResolveChildCloneRulesValueOwnership(manageability Manageability, childCloneRulesCustomized bool) ObjectSpecValueDecision {
	return ResolveObjectSpecValueOwnership(manageability, childCloneRulesCustomized)
}

// ResolveExclusiveSiblingFieldsValueOwnership is the ownership oracle for
// per-spec _System_Object.ExclusiveSiblingFields decisions.
func ResolveExclusiveSiblingFieldsValueOwnership(manageability Manageability, exclusiveSiblingFieldsCustomized bool) ObjectSpecValueDecision {
	return ResolveObjectSpecValueOwnership(manageability, exclusiveSiblingFieldsCustomized)
}

// ResolveLockRuleValueOwnership is the sole ownership oracle for per-spec
// _System_Object.LockRule decisions.
//
// Policy (mirrors DefaultChildRows and ResolveObjectSpecValueOwnership):
//   - ManageabilityLocked + any lockRuleCustomized → exact match required (locked
//     manageability means the pack owns LockRule even if admin touched it;
//     lockRuleCustomized=1 on a locked surface is structural drift, not an override)
//   - ManageabilityDefaultsOnly + lockRuleCustomized=true → live override allowed
//     (admin explicitly transferred LockRule ownership)
//   - ManageabilityDefaultsOnly + lockRuleCustomized=false → exact match required
//     (unrelated object-row customization, e.g. label/icon edit, must not transfer
//     ownership of the executable LockRule fact — IsCustomized is too coarse)
func ResolveLockRuleValueOwnership(manageability Manageability, lockRuleCustomized bool) ObjectSpecValueDecision {
	return ResolveObjectSpecValueOwnership(manageability, lockRuleCustomized)
}

// ResolveListFieldsValueOwnership is the ownership oracle for per-spec
// _System_Object.ListFields decisions. Standalone list_fields components remain
// defaults_only and may preserve admin overrides; object_spec listFields must use
// this column-scoped bit so ManageabilityLocked specs fail closed on live drift.
func ResolveListFieldsValueOwnership(manageability Manageability, listFieldsCustomized bool) ObjectSpecValueDecision {
	return ResolveObjectSpecValueOwnership(manageability, listFieldsCustomized)
}
