package bootstrap

// 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: scoped globally (empty
// ScopeColumn), keyed by Name (uq_sa_name). InitializeStandardActions
// reconciles it by the actually-persisted row Id (not by re-deriving
// StandardActionID(def.Name)), because ON DUPLICATE KEY UPDATE matches
// on Name — a legacy or manually-loaded row with the same Name but a
// non-canonical Id keeps its existing Id through upsert. The reconcile
// MUST see that real Id in `keep` or it would soft-delete the row as an
// orphan. See InitializeStandardActions for the SELECT-after-upsert path.
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,
	}
)
