package sfcrmappservice

import (
	"encoding/json"

	mutationsemantic "github.com/pingcap-inc/nexuscrm-contract/pkg/runtime/recordmutationv1"
)

// canonicalActionInputs projects one decoded CRM action input through the
// neutral Runtime source-JSON grammar before it is claimed as CanonicalInputs.
// encoding/json alone escapes HTML characters and U+2028/U+2029, which is not
// canonical under that contract.
func canonicalActionInputs(input map[string]any) ([]byte, error) {
	raw, err := json.Marshal(input)
	if err != nil {
		return nil, err
	}
	canonical, err := mutationsemantic.CanonicalSourceJSON(string(raw))
	if err != nil {
		return nil, err
	}
	return []byte(canonical), nil
}
