// Package seedrows holds the seed-row parsers that need a backend dependency
// (here, the kernel apperrors package). The pure stdlib-only data shapes for
// this family live in the contract module's seedrows package; this package
// re-exports them so callers have a single import for the action-def family.
package seedrows

import (
	"encoding/json"

	apperrors "github.com/nexuscrm/kernel/pkg/errors"
	contract "github.com/pingcap-inc/nexuscrm-contract/pkg/seedrows"
)

// StandardActionDef and its nested authored shapes are stdlib-only and live in
// the contract module. They are aliased here so a kernel caller of
// ParseStandardActionDefs needs only one import.
type (
	StandardActionDef                    = contract.StandardActionDef
	StandardActionSchemaDef              = contract.StandardActionSchemaDef
	StandardActionDefaultDef             = contract.StandardActionDefaultDef
	StandardActionGuardDef               = contract.StandardActionGuardDef
	StandardActionCustomPermissionDef    = contract.StandardActionCustomPermissionDef
	StandardActionInternalAccessScopeDef = contract.StandardActionInternalAccessScopeDef
)

// ParseStandardActionDefs decodes the authored standard-action pack payload.
func ParseStandardActionDefs(raw []byte) ([]StandardActionDef, error) {
	var defs []StandardActionDef
	if err := json.Unmarshal(raw, &defs); err != nil {
		return nil, apperrors.NewInternalError("failed to parse standard_actions.json", err)
	}
	return defs, nil
}
