package seedrows

// StandardActionDef describes one row in the _System_StandardAction registry
// together with its input/output schema, per-object field defaults, and
// permission guards. Authored as JSON and seeded idempotently at bootstrap
// with IsCustomized=1 rows treated as admin-owned and never overwritten,
// except for internal access scopes, which are L1 standard core only.
type StandardActionDef struct {
	Name              string `json:"name"`
	Label             string `json:"label"`
	Description       string `json:"description,omitempty"`
	FlowDeveloperName string `json:"flowDeveloperName"`
	// PreviewFlowDeveloperName is an optional Flow that produces preview
	// output values (e.g. campaign attribution) for the action. NULL means
	// no preview producer exists for this action.
	PreviewFlowDeveloperName *string  `json:"previewFlowDeveloperName,omitempty"`
	Category                 string   `json:"category,omitempty"`
	RequiredPermissions      []string `json:"requiredPermissions,omitempty"`
	RendererID               string   `json:"rendererId,omitempty"`
	// TargetObjects are the SObject API names this action applies to
	// (for example, the object API names targeted by an L1 action). An EMPTY slice means the action
	// has no object-level placement; it is not rendered on any object
	// page. Admins who want an action visible on a given SObject MUST
	// list that SObject explicitly; silence = hidden. This is metadata-
	// driven's explicit-over-implicit rule: the default state of "where
	// does this show up" is "nowhere" unless declared. If we ever need a
	// true "all objects" placement (e.g. a global-quick-action bar), add
	// a dedicated field like IsGlobal / PlacementScope rather than
	// overloading the empty array with a second semantic.
	//
	// Drives metadata-driven button discovery: GET /actions/standard
	// returns this field, frontend filters actions by membership in the
	// current object's name.
	TargetObjects []string `json:"targetObjects,omitempty"`
	// HeaderFallbackEligible lets an action opt out of generic unauthored
	// record-header fallback surfaces. nil/true preserve legacy eligibility.
	HeaderFallbackEligible *bool                      `json:"headerFallbackEligible,omitempty"`
	IsAtomic               bool                       `json:"isAtomic,omitempty"`
	SortOrder              int                        `json:"sortOrder,omitempty"`
	Inputs                 []StandardActionSchemaDef  `json:"inputs,omitempty"`
	Outputs                []StandardActionSchemaDef  `json:"outputs,omitempty"`
	FieldDefaults          []StandardActionDefaultDef `json:"fieldDefaults,omitempty"`
	InputGuards            []StandardActionGuardDef   `json:"inputGuards,omitempty"`
	// VisibilityCondition is a generic client-side expression evaluated against
	// the current record before the action button is rendered. NULL / empty
	// means always visible. Platform code is an evaluator only; condition
	// expressions are authored by L1 app packs or L2 admin metadata.
	VisibilityCondition *string `json:"visibilityCondition,omitempty"`
	// InternalAccessScopes declares conversion/bookkeeping reads and writes
	// owned by the standard action itself. Runtime consumes these as scoped
	// metadata; no action/object special-case branch is allowed in query or
	// persistence code.
	InternalAccessScopes []StandardActionInternalAccessScopeDef `json:"internalAccessScopes,omitempty"`
	// CustomPermissions declares the _System_CustomPermission rows this
	// action depends on. Declaring them inline keeps the action self-
	// describing: adding a new policy-style permission is a pure data
	// change in standard_actions.json, no Go edit required.
	CustomPermissions []StandardActionCustomPermissionDef `json:"customPermissions,omitempty"`
}

// StandardActionCustomPermissionDef is one row in _System_CustomPermission.
type StandardActionCustomPermissionDef struct {
	APIName     string `json:"apiName"`
	Label       string `json:"label"`
	Description string `json:"description,omitempty"`
}

// StandardActionSchemaDef is one row in _System_ActionSchema.
type StandardActionSchemaDef struct {
	APIName                   string `json:"apiName"`
	DataType                  string `json:"dataType"`
	ReferenceTo               string `json:"referenceTo,omitempty"`
	Label                     string `json:"label,omitempty"`
	UISection                 string `json:"uiSection,omitempty"`
	UIMode                    string `json:"uiMode,omitempty"`
	TargetObject              string `json:"targetObject,omitempty"`
	TargetFieldAPIName        string `json:"targetFieldAPIName,omitempty"`
	PrefillSourceFieldAPIName string `json:"prefillSourceFieldAPIName,omitempty"`
	RequiredPicklistTag       string `json:"requiredPicklistTag,omitempty"`
	MappingSourceObject       string `json:"mappingSourceObject,omitempty"`
	MappingActionType         string `json:"mappingActionType,omitempty"`
	IsCollection              bool   `json:"isCollection,omitempty"`
	IsRequired                bool   `json:"isRequired,omitempty"`
	Description               string `json:"description,omitempty"`
	SortOrder                 int    `json:"sortOrder,omitempty"`
}

// StandardActionDefaultDef is one row in _System_ActionFieldDefault.
type StandardActionDefaultDef struct {
	TargetObject string `json:"targetObject"`
	FieldAPIName string `json:"fieldAPIName"`
	ValueFormula string `json:"valueFormula"`
	Condition    string `json:"condition,omitempty"`
	Priority     int    `json:"priority,omitempty"`
}

// StandardActionGuardDef is one row in _System_ActionInputGuard.
type StandardActionGuardDef struct {
	Condition          string `json:"condition"`
	RequiredPermission string `json:"requiredPermission,omitempty"`
	RequiredObject     string `json:"requiredObject,omitempty"`
	RequiredOperation  string `json:"requiredOperation,omitempty"`
	ErrorMessage       string `json:"errorMessage,omitempty"`
	// GatedInput is the action-input APIName or mode-control input this guard
	// targets. When non-empty,
	// GET /actions/standard surfaces the per-caller permission verdict so
	// clients can render, require, disable, or hide the matching input path. When
	// empty, the guard is a whole-action precondition.
	GatedInput string `json:"gatedInput,omitempty"`
	SortOrder  int    `json:"sortOrder,omitempty"`
}

// StandardActionInternalAccessScopeDef is one row in
// _System_StandardActionInternalAccessScope.
type StandardActionInternalAccessScopeDef struct {
	ObjectAPIName string `json:"objectApiName"`
	Operation     string `json:"operation"`
	Reason        string `json:"reason,omitempty"`
}
