package packs

// PackTable descriptors for the _System_Action* family.
//
// The KeyColumns lists MUST match the uq_* unique-index columns declared
// in system_tables.json for each table; TestPackTableDescriptors_MatchSystemTablesJSON
// asserts this at test time. If the DDL unique key changes, update these
// lists AND the Id-derivation function for the table in the same commit —
// see actionInputGuardID for the current key formula.
//
// packTableStandardAction is the PARENT table: keyed by Name (uq_sa_name).
// Owner-scoped app packs reconcile _System_StandardAction by OwnerPack in
// InitializeStandardActionsForOwner; this descriptor remains for the legacy
// ownerless bootstrap wrapper. In both paths the keep set is built from the
// actually-persisted row Id (not by re-deriving StandardActionID(def.Name)),
// because ON DUPLICATE KEY UPDATE matches on Name and preserves a legacy or
// manually-loaded row's non-canonical Id.
var (
	packTableStandardAction = PackTable{
		Name:        tableStandardAction, // _System_StandardAction
		ScopeColumn: "",                  // global reconcile (no scope predicate)
		KeyColumns:  []string{"Name"},    // uq_sa_name
		IdColumn:    "Id",
	}

	packTableActionSchema = PackTable{
		Name:        tableActionSchema, // _System_ActionSchema
		ScopeColumn: "StandardActionId",
		KeyColumns:  []string{"StandardActionId", "Direction", "APIName"}, // uq_as_field
		IdColumn:    "Id",
	}

	packTableActionFieldDefault = PackTable{
		Name:        tableActionFieldDefault, // _System_ActionFieldDefault
		ScopeColumn: "StandardActionId",
		KeyColumns:  []string{"StandardActionId", "TargetObject", "FieldAPIName", "Priority"}, // uq_afd_key
		IdColumn:    "Id",
	}

	packTableActionInputGuard = PackTable{
		Name:        tableActionInputGuard, // _System_ActionInputGuard
		ScopeColumn: "StandardActionId",
		KeyColumns:  []string{"StandardActionId", "Condition", "GuardKey"}, // uq_aig_rule
		IdColumn:    "Id",
	}

	packTableStandardActionInternalAccessScope = PackTable{
		Name:        tableStandardActionInternalAccessScope, // _System_StandardActionInternalAccessScope
		ScopeColumn: "StandardActionId",
		KeyColumns:  []string{"StandardActionId", "ObjectApiName", "Operation"}, // uq_saias_scope
		IdColumn:    "Id",
		L1Only:      true,
	}
)
